xsl-list
[Top] [All Lists]

Re: increment variable with xsl:for-each

2004-03-26 03:06:17
Tuan Luu wrote:

hello I'm looking for a code to increment a variable in xsl:for-each loop

I ended up here:
<xsl:variable name="a">1</xsl:variable>

<xsl:for-each select="name">

You may be looking for:
<xsl:variable name="a" select="count(name)"/>
or possibly:
<xsl:for-each select="name">
   <count><xsl:value-of select="position()"/></count>
</xsl:for-each>

The kind of information you are probably looking for when you use $a is probably already provided. If not, use a recursive template as mentioned by several other people here.

<xsl:value of select="{$a+1}"/>
<xsl:value of select="{$a}"/>

</xsl:for-each>


thanks for any answer