title: Passing parameters to XSLT Stylesheet via .NET
body: <p>I'm trying to pass a parameter to an XSLT stylesheet, but all i'm getting is an empty xml document when the document is transformed using XSlCompiledTransform.</p>
  
  <p>This is the C# method used to add the parameters(after adding in people's suggestions)</p>
  
  <pre><code>private static void CreateHierarchy(string manID)
      {
  
          string man_ID = manID;
  
          XsltArgumentList argsList = new XsltArgumentList();
          argsList.AddParam("Boss_ID","",man_ID);
  
          XslCompiledTransform transform = new XslCompiledTransform();
          transform.Load("htransform.xslt");
  
          using (StreamWriter sw = new StreamWriter("output.xml"))
          {
              transform.Transform("LU AIB.xml", argsList, sw);
          } 
  
  
      }
  </code></pre>
  
  <p>and here is the stylesheet. The parameter i'm passing in is 'Boss_ID'</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8"?&gt;
     &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
     &lt;xsl:output method="xml" indent="yes" /&gt;
     &lt;xsl:template match="OrgDoc"&gt;
       &lt;xsl:param name="Boss_ID"&gt;&lt;/xsl:param&gt;
      &lt;xsl:processing-instruction name="xml-stylesheet"&gt;
      &lt;xsl:text&gt;type="text/xsl" href="..\styles\orgcharts.xsl" &lt;/xsl:text&gt;
    &lt;/xsl:processing-instruction&gt;
      &lt;OrgDoc&gt;
        &lt;xsl:for-each select="PosDets[@OC_Man = $Boss_ID]"&gt;
        &lt;PosDets OC_Pos="{@OC_Pos}" OC_Sub="{@OC_Sub}" OC_Man="{@OC_Man}" OC_Ttl="{@OC_Ttl}" OC_Rnk="{@OC_Rnk}" OC_Bdg="{@OC_Bdg}" OC_Fnd="{@OC_Fnd}"   OC_OL3="{@OC_OL3}"    OC_Tmp="{@OC_Tmp}"&gt;
            &lt;xsl:apply-templates select="../PosDets"&gt;
              &lt;xsl:with-param name="mgrid" select="@OC_Pos"/&gt;
            &lt;/xsl:apply-templates&gt;
          &lt;/PosDets&gt;  
        &lt;/xsl:for-each&gt;
      &lt;/OrgDoc&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="PosDets" &gt; 
      &lt;xsl:param name="mgrid" /&gt;
      &lt;xsl:if test="@OC_Man=$mgrid" &gt;
        &lt;PosDets OC_Pos="{@OC_Pos}" OC_Sub="{@OC_Sub}" OC_Man="{@OC_Man}" OC_Ttl="{@OC_Ttl}" OC_Rnk="{@OC_Rnk}" OC_Bdg="{@OC_Bdg}" OC_Fnd="{@OC_Fnd}"   OC_OL3="{@OC_OL3}"    OC_Tmp="{@OC_Tmp}"&gt;
          &lt;xsl:apply-templates select="../PosDets"&gt;
            &lt;xsl:with-param name="mgrid" select="@OC_Pos"/&gt;
          &lt;/xsl:apply-templates&gt;
        &lt;/PosDets&gt;  
      &lt;/xsl:if&gt;
    &lt;/xsl:template&gt;
  
  
     &lt;/xsl:stylesheet&gt;  
  </code></pre>
  
  <p>I can't post all of the input document as it's confidential info, but here's a brief sanitised version</p>
  
  <pre><code>&lt;OrgDoc&gt;&lt;PosDets OC_Pos="161" OC_Man="9" OC_Ttl="Boss" OC_Rank="" OC_OL3="LU AIB" OC_Bdg="Has Budget" OC_Fnd="Payroll" OC_Sub="" OC_Tmp="" /&gt;&lt;PosDets OC_Pos="190" OC_Man="161" OC_Ttl="Boss" OC_Rank="" OC_OL3="LU AIB" OC_Bdg="Has Budget" OC_Fnd="Payroll" OC_Sub="" OC_Tmp="" /&gt;&lt;PosDets OC_Pos="199" OC_Man="190" OC_Ttl="Boss" OC_Rank="" OC_OL3="LU AIB" OC_Bdg="Has Budget" OC_Fnd="Payroll" OC_Sub="" OC_Tmp="" /&gt;&lt;/OrgDoc&gt;
  </code></pre>
  
  <p>Can anyone help?</p>
  
  <p>Thanks</p>