title: XSLT: sum of tree fragment will always return 0 !
body: <p>I am stuck with a problem which seems stupid but I cannot find out the solution... With XLST, I need to sum a list of values calculated by a template. So I stored these values in a tree structure (a list of "Number" elements contained in a root element "Numbers"). But whatever I try to do with this self-made list, it will return either nothing, 0 or an error...</p>
  
  <p>Does someone know what I am doing wrong ?</p>
  
  <pre><code>&lt;!-- create the tree fragment --&gt;
  &lt;xsl:variable name="_subTotals"&gt;
      &lt;Numbers&gt;
          &lt;xsl:for-each select="List"&gt;
              &lt;xsl:variable name="_Size"&gt;
                  &lt;xsl:call-template name="GetSize"&gt;
                      &lt;xsl:with-param name="_value" select="@value"/&gt;
                  &lt;/xsl:call-template&gt;
              &lt;/xsl:variable&gt;
              &lt;Number&gt;
                  &lt;xsl:value-of select="$_Size"/&gt;
              &lt;/Number&gt;
          &lt;/xsl:for-each&gt;
      &lt;/Numbers&gt;
  &lt;/xsl:variable&gt;
  
  &lt;!-- this returns an error: expression must result into a node-set --&gt;
  &lt;xsl:message terminate="no"&gt;
      &lt;xsl:value-of select="sum($_subTotals/Numbers/Number)"/&gt;
  &lt;/xsl:message&gt;
  
  &lt;!-- transform the tree fragment into a node-set
  &lt;xsl:variable name="_Total" select="msxsl:node-set($_subTotals)"/&gt;
  
  &lt;!-- returns nothing --&gt;
  &lt;xsl:for-each select="$_Total/Numbers/Number"&gt;
      &lt;xsl:message terminate="no"&gt;
          &lt;xsl:value-of select="@value"/&gt;
      &lt;/xsl:message&gt;
  &lt;/xsl:for-each&gt;
  
  &lt;!-- returns 0 --&gt;
  &lt;xsl:value-of select="sum($_Total/Numbers/Number)"/&gt;
  </code></pre>