XSLT incrementing count

J

John Wilkinson

Hi,
I am new to XSLT. My problem is that I wish to create an HTML table, and
give each row an incrementing number from 1.This would increment every
itteration of a for-each loop.
The XSLT fragment I have tried is:

<xsl:variable name="test" select="0"></xsl:variable>
<table border="1">
<tbody>
<tr bgcolor="#9acd32">
<th>Number</th>
</tr>
<xsl:for-each select="amsal_coverage_stats/core">
<tr>
<td>

<xsl:value-of select="$test+1"></xsl:value-of>

</td>
</tr>
</xsl:for-each>

However this just has the value 1.

Any help would be much appreciated.

Thanks.
John.
 
M

Martin Honnen

John said:
My problem is that I wish to create an HTML table, and
give each row an incrementing number from 1.This would increment every
itteration of a for-each loop.
<xsl:for-each select="amsal_coverage_stats/core">
<tr>
<td>

<xsl:value-of select="$test+1"></xsl:value-of>

You can use
<xsl:value-of select="position()" />

For more advanced stuff you might want to check the <xsl:number> statement.
 
T

toudidel

don't use <xsl:for-each> element, it's terrible. Instead of it
<xsl:apply-templates> with <xsl:value-of select="position()"/> in it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top