title: XSLT increment recursion template
body: <p>Please help me solve increment issue.
  Is there a way to make an increment numbering list without using position(), number() or xpath expressions?</p>
  
  <p>Here is the sample xml document that I want to process using xslt 1.0:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
      &lt;text&gt;a&lt;/text&gt;
      &lt;text&gt;b&lt;/text&gt;
      &lt;text&gt;c&lt;/text&gt;
      &lt;line&gt;
          &lt;test&gt;5&lt;/test&gt;
          &lt;test&gt;6&lt;/test&gt;
      &lt;/line&gt;
      &lt;line&gt;
          &lt;test&gt;7&lt;/test&gt;
          &lt;test&gt;8&lt;/test&gt;
      &lt;/line&gt;
      &lt;line&gt;
          &lt;test&gt;9&lt;/test&gt;
          &lt;test&gt;10&lt;/test&gt;
      &lt;/line&gt;
      &lt;line&gt;
          &lt;test&gt;11&lt;/test&gt;
          &lt;test&gt;12&lt;/test&gt;
      &lt;/line&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>What I want to get is an increment variable, that increases with each <code>&lt;line&gt;</code> node. 
  Here is the desired output with <code>&lt;pos&gt;</code> increment:</p>
  
  <pre><code>&lt;?xml version='1.0' ?&gt;
  &lt;line&gt;
    &lt;line-item&gt;
      &lt;pos&gt;1&lt;/pos&gt;
      &lt;value&gt;5&lt;/value&gt;
      &lt;value&gt;6&lt;/value&gt;
    &lt;/line-item&gt;
    &lt;line-item&gt;
      &lt;pos&gt;2&lt;/pos&gt;
      &lt;value&gt;7&lt;/value&gt;
      &lt;value&gt;8&lt;/value&gt;
    &lt;/line-item&gt;
    &lt;line-item&gt;
      &lt;pos&gt;3&lt;/pos&gt;
      &lt;value&gt;9&lt;/value&gt;
      &lt;value&gt;10&lt;/value&gt;
    &lt;/line-item&gt;
    &lt;line-item&gt;
      &lt;pos&gt;4&lt;/pos&gt;
      &lt;value&gt;11&lt;/value&gt;
      &lt;value&gt;12&lt;/value&gt;
    &lt;/line-item&gt;
  &lt;/line&gt;
  </code></pre>
  
  <p>Here is my style sheet transformation that I managed to come up with so far:</p>
  
  <pre><code>&lt;?xml version='1.0'?&gt;
  &lt;xsl:stylesheet version="1.0" id="1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="xml" indent="yes" /&gt;
  
  &lt;xsl:template match="/"&gt;
      &lt;xsl:variable name="total_lines" select="count(root/line)" /&gt;
  
      &lt;line&gt;
          &lt;xsl:call-template name="iter"&gt;
              &lt;xsl:with-param name="end" select="$total_lines" /&gt;
          &lt;/xsl:call-template&gt;
      &lt;/line&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template name="iter"&gt;
      &lt;xsl:param name="counter" select="1" /&gt;
      &lt;xsl:param name="end" /&gt;
  
      &lt;xsl:if test="$counter &amp;lt;= $end"&gt;
          &lt;line-item&gt;
              &lt;pos&gt;
                  &lt;xsl:value-of select="$counter" /&gt;
              &lt;/pos&gt;
  
              &lt;xsl:apply-templates select="root/line/test" /&gt;
          &lt;/line-item&gt;
  
          &lt;xsl:call-template name="iter"&gt;
              &lt;xsl:with-param name="counter" select="$counter + 1" /&gt;
              &lt;xsl:with-param name="end" select="$end" /&gt;
          &lt;/xsl:call-template&gt; 
      &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="/root/line/test" &gt; 
      &lt;value&gt;
          &lt;xsl:value-of select="." /&gt;
      &lt;/value&gt;
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>And here is the actual output, the problem is that it repeats every <code>&lt;value&gt;</code> in the every <code>&lt;line-item&gt;</code> node, and this is not what I intended to get in result.</p>
  
  <pre><code>&lt;?xml version='1.0' ?&gt;
  &lt;line&gt;
    &lt;line-item&gt;
      &lt;pos&gt;1&lt;/pos&gt;
      &lt;value&gt;5&lt;/value&gt;
      &lt;value&gt;6&lt;/value&gt;
      &lt;value&gt;7&lt;/value&gt;
      &lt;value&gt;8&lt;/value&gt;
      &lt;value&gt;9&lt;/value&gt;
      &lt;value&gt;10&lt;/value&gt;
      &lt;value&gt;11&lt;/value&gt;
      &lt;value&gt;12&lt;/value&gt;
    &lt;/line-item&gt;
    &lt;line-item&gt;
      &lt;pos&gt;2&lt;/pos&gt;
      &lt;value&gt;5&lt;/value&gt;
      &lt;value&gt;6&lt;/value&gt;
      &lt;value&gt;7&lt;/value&gt;
      &lt;value&gt;8&lt;/value&gt;
      &lt;value&gt;9&lt;/value&gt;
      &lt;value&gt;10&lt;/value&gt;
      &lt;value&gt;11&lt;/value&gt;
      &lt;value&gt;12&lt;/value&gt;
    &lt;/line-item&gt;
    &lt;line-item&gt;
      &lt;pos&gt;3&lt;/pos&gt;
      &lt;value&gt;5&lt;/value&gt;
      &lt;value&gt;6&lt;/value&gt;
      &lt;value&gt;7&lt;/value&gt;
      &lt;value&gt;8&lt;/value&gt;
      &lt;value&gt;9&lt;/value&gt;
      &lt;value&gt;10&lt;/value&gt;
      &lt;value&gt;11&lt;/value&gt;
      &lt;value&gt;12&lt;/value&gt;
    &lt;/line-item&gt;
    &lt;line-item&gt;
      &lt;pos&gt;4&lt;/pos&gt;
      &lt;value&gt;5&lt;/value&gt;
      &lt;value&gt;6&lt;/value&gt;
      &lt;value&gt;7&lt;/value&gt;
      &lt;value&gt;8&lt;/value&gt;
      &lt;value&gt;9&lt;/value&gt;
      &lt;value&gt;10&lt;/value&gt;
      &lt;value&gt;11&lt;/value&gt;
      &lt;value&gt;12&lt;/value&gt;
    &lt;/line-item&gt;
  &lt;/line&gt;
  </code></pre>
  
  <p>I read through the topics all over the internet and it seems that i'am stuck. 
  Please help me.
  P.S. Sorry for the long post.</p>