title: Applying XSLT in .NET different (incorrect) result vs. Notepad++
body: <p>I have an XML file, in which an attribute on the parent element drives logic for transformation of child elements.</p>
  
  <p>When I apply this XSLT transform in Notepad++'s XML Tools plugin, I get correct and expected result. However when I use <code>XslCompiledTransform</code> the result comes out as if it's missing the declared variable. I tried debugging XSLT in Visual Studio and the variable's value is always <code>NULL</code>.</p>
  
  <p>What am I doing incorrectly in .NET?</p>
  
  <p>XML:</p>
  
  <pre><code> &lt;summary&gt;
     &lt;section format="2" title="ACCOUNT SUMMARY"&gt;
          &lt;section_box&gt;
            &lt;subTotal&gt;
              &lt;description&gt;BALANCE FORWARD&lt;/description&gt;
              &lt;amount /&gt;
            &lt;/subTotal&gt;
            &lt;line&gt;
              &lt;description&gt;Previous Balance&lt;/description&gt;
              &lt;amount&gt;$155.64&lt;/amount&gt;
            &lt;/line&gt;
            &lt;line&gt;
              &lt;description&gt;Payments Received&lt;/description&gt;
              &lt;amount&gt;$155.64 CR&lt;/amount&gt;
            &lt;/line&gt;
            &lt;subTotal&gt;
              &lt;description&gt;TOTAL BALANCE FORWARD&lt;/description&gt;
              &lt;amount&gt;$0.00&lt;/amount&gt;
            &lt;/subTotal&gt;
          &lt;/section_box&gt;
     &lt;/section&gt;
     &lt;section format="3" title="ACCOUNT DETAILS"&gt;
          &lt;section_box&gt;
            &lt;line&gt;        &lt;label&gt;Charge&lt;/label&gt;
              &lt;description&gt;Monthly Charge for Service&lt;/description&gt;
              &lt;amount&gt;$155.64&lt;/amount&gt;
            &lt;/line&gt;
            &lt;subTotal&gt;
              &lt;description&gt;TOTAL NEW BALANCE&lt;/description&gt;
              &lt;amount&gt;$155.64&lt;/amount&gt;
            &lt;/subTotal&gt;
          &lt;/section_box&gt;
     &lt;/section&gt;
   &lt;/summary&gt;
  </code></pre>
  
  <p>XSLT:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:output method="xml" omit-xml-declaration="yes" indent="yes" /&gt;
      &lt;xsl:template match="summary"&gt;
          &lt;summary&gt;
              &lt;xsl:apply-templates select="section" /&gt;
          &lt;/summary&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template match="section"&gt;
          &lt;xsl:variable name="row-format" select="@format" /&gt;
          &lt;xsl:if test="@title"&gt;
              &lt;title&gt;
                  &lt;xsl:value-of select="@title" /&gt;
              &lt;/title&gt;
          &lt;/xsl:if&gt;
          &lt;xsl:apply-templates select="line|subTotal|section_box"&gt;
              &lt;xsl:with-param name="row-format" select="$row-format" /&gt;
          &lt;/xsl:apply-templates&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template match="line"&gt;
          &lt;xsl:param name="row-format" /&gt;
          &lt;line&gt;
              &lt;xsl:attribute name="format"&gt;
                  &lt;xsl:value-of select="$row-format"/&gt;
              &lt;/xsl:attribute&gt;
              &lt;xsl:if test="$row-format = '2'"&gt;
                  &lt;description&gt;
                      &lt;xsl:value-of select="description" /&gt;
                  &lt;/description&gt;
                  &lt;date&gt;
                      &lt;xsl:value-of select="date" /&gt;
                  &lt;/date&gt;
                  &lt;amount&gt;
                      &lt;xsl:value-of select="amount" /&gt;
                  &lt;/amount&gt;
              &lt;/xsl:if&gt;
              &lt;xsl:if test="$row-format = '3'"&gt;
                  &lt;label&gt;
                      &lt;xsl:value-of select="label" /&gt;
                  &lt;/label&gt;
                  &lt;description&gt;
                      &lt;xsl:value-of select="description" /&gt;
                  &lt;/description&gt;
                  &lt;amount&gt;
                      &lt;xsl:value-of select="amount" /&gt;
                  &lt;/amount&gt;
              &lt;/xsl:if&gt;
          &lt;/line&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template match="subtotal|subTotal"&gt;
          &lt;xsl:param name="row-format" /&gt;
          &lt;subtotal&gt;
              &lt;description&gt;
                  &lt;xsl:value-of select="description" /&gt;
              &lt;/description&gt;
              &lt;amount&gt;
                  &lt;xsl:value-of select="amount" /&gt;
              &lt;/amount&gt;
          &lt;/subtotal&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Expected Result (and from Notepad++, note <code>line</code> elements contents and <code>format</code> attribute is correct):</p>
  
  <pre><code>&lt;summary&gt;
      &lt;title&gt;ACCOUNT SUMMARY&lt;/title&gt;
      &lt;subtotal&gt;
          &lt;description&gt;BALANCE FORWARD&lt;/description&gt;
          &lt;amount/&gt;
      &lt;/subtotal&gt;
      &lt;line format="2"&gt;
          &lt;description&gt;Previous Balance&lt;/description&gt;
          &lt;date/&gt;
          &lt;amount&gt;$155.64&lt;/amount&gt;
      &lt;/line&gt;
      &lt;line format="2"&gt;
          &lt;description&gt;Payments Received&lt;/description&gt;
          &lt;date/&gt;
          &lt;amount&gt;$155.64 CR&lt;/amount&gt;
      &lt;/line&gt;
      &lt;subtotal&gt;
          &lt;description&gt;TOTAL BALANCE FORWARD&lt;/description&gt;
          &lt;amount&gt;$0.00&lt;/amount&gt;
      &lt;/subtotal&gt;
      &lt;title&gt;ACCOUNT DETAILS&lt;/title&gt;
      &lt;line format="3"&gt;
          &lt;label&gt;Charge&lt;/label&gt;
          &lt;description&gt;Monthly Charge for Service&lt;/description&gt;
          &lt;amount&gt;$155.64&lt;/amount&gt;
      &lt;/line&gt;
      &lt;subtotal&gt;
          &lt;description&gt;TOTAL NEW BALANCE&lt;/description&gt;
          &lt;amount&gt;$155.64&lt;/amount&gt;
      &lt;/subtotal&gt;
  &lt;/summary&gt;
  </code></pre>
  
  <p>.NET Produces (note missing content of <code>line</code>s because no matching <code>format</code> is found; because it's <code>NULL</code>):</p>
  
  <pre><code>&lt;summary&gt;
      &lt;title&gt;ACCOUNT SUMMARY&lt;/title&gt;
      &lt;subtotal&gt;
          &lt;description&gt;BALANCE FORWARD&lt;/description&gt;
          &lt;amount/&gt;
      &lt;/subtotal&gt;
      &lt;line format="" /&gt;
      &lt;line format="" /&gt;
      &lt;subtotal&gt;
          &lt;description&gt;TOTAL BALANCE FORWARD&lt;/description&gt;
          &lt;amount&gt;$0.00&lt;/amount&gt;
      &lt;/subtotal&gt;
      &lt;title&gt;ACCOUNT DETAILS&lt;/title&gt;
      &lt;line format="" /&gt;
      &lt;subtotal&gt;
          &lt;description&gt;TOTAL NEW BALANCE&lt;/description&gt;
          &lt;amount&gt;$155.64&lt;/amount&gt;
      &lt;/subtotal&gt;
  &lt;/summary&gt;
  </code></pre>
  
  <p>.NET code executed:</p>
  
  <pre><code>Dim compiled As New XslCompiledTransform(True)
  compiled.Load("C:\summary.xsl")
  compiled.Transform("C:\Summary.xml", "C:\TransformedSummary.xml")
  </code></pre>