title: XSLT line counter - is it that hard?
body: <p>I have cheated every time I've needed to do a line count in XSLT by using JScript, but in this case I can't do that.  I simply want to write out a line counter throughout an output file.  This basic example has a simple solution:</p>
  
  <pre><code>&lt;xsl:for-each select="Records/Record"&gt;
     &lt;xsl:value-of select="position()"/&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>Output would be:</p>
  
  <p>1</p>
  
  <p>2</p>
  
  <p>3</p>
  
  <p>4</p>
  
  <p>etc...</p>
  
  <p>But what if the structure is more complex with nested foreach's :</p>
  
  <pre><code>&lt;xsl:for-each select="Records/Record"&gt;
     &lt;xsl:value-of select="position()"/&gt;
     &lt;xsl:for-each select="Records/Record"&gt;
         &lt;xsl:value-of select="position()"/&gt;
     &lt;/xsl:for-each&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>Here, the inner foreach would just reset the counter (so you get 1, 1, 2, 3, 2, 1, 2, 3, 1, 2 etc).  Does anyone know how I can output the position in the file (ie. a line count)?</p>