title: XSLT - Count nodes for each xml document
body: <p>I'm new with xsl and faced an issue with counting nodes in multiple xml documents. Here is my XSLT fragment:</p>
  
  <pre><code>&lt;xsl:variable name="count"&gt;
      &lt;xsl:for-each select="document(./log/@file)/testResults/*[not(@lb = preceding::*/@lb)]"&gt;
              &lt;xsl:value-of select="count(../*[@lb = current()/@lb])"/&gt;
      &lt;/xsl:for-each&gt;
  &lt;/xsl:variable&gt;
  </code></pre>
  
  <p>where <strong>./log/@file</strong> maches few xml documents.
  An xml document sample:</p>
  
  <pre><code>&lt;testResults version="1.2"&gt;
          &lt;sample t="63" lt="0" ts="1343919489839" s="true" lb="jp@gc - Dummy Sampler" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="114"/&gt;
          &lt;sample t="62" lt="0" ts="1343919489903" s="true" lb="jp@gc - Dummy Sampler" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="114"/&gt;
          &lt;sample t="58" lt="0" ts="1343919490063" s="true" lb="jp@gc - Dummy Sampler" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="114"/&gt;
          &lt;sample t="13" lt="0" ts="1343919490210" s="true" lb="jp@gc - Dummy Sampler" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="114"/&gt;
          &lt;sample t="37" lt="0" ts="1343919490223" s="true" lb="jp@gc - Dummy Sampler" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="114"/&gt;
  &lt;/testResults&gt;
  </code></pre>
  
  <p>I have same structure for all parsed documents.</p>
  
  <p>And an issue finally...
  count function returns count for one document correctly. But next count result will concatinated to previous one. My target is to sum the results of each iteration.</p>
  
  <p>So if I'll have 15 maches for 1st iteration and 4 matches for second iteration count variable will be set to 154.</p>
  
  <p>Could you please help with this?</p>
  
  <p>P.s. I'm counting <strong>child elements</strong> of <strong>testResults</strong> grouping by <strong>lb</strong> attribute</p>
  
  <p>P.p.s <strong>xsl</strong> version is <strong>1.0</strong></p>
  
  <p>Thanks,
  Valeriy</p>