Counting with XSL
XSL can be difficult to use – some programming tasks are extremely complicated or even impossible if you think of XSL as a programming language. For example, let’s say you want to show the numbers 1 – 10. This is very difficult because all variables in XSL are immutable, and they cannot be redeclared in the same scope. That means there is no concept of X = X + 1. The solution to this is recursion. Here’s an example of displaying 10 table rows and numbering them 11 – 20 (for example, if you were showing the second page of 10 search results)
<xsl:template name=”numbered-rows”>
<xsl:param name=”start”/> <!– starting value –>
<xsl:param name=”increment”/> <!– increment by –>
<xsl:param name=”max”/> <!– what number to stop at –>
<!– you may need additional params to show your table data –>
<tr>
<td><xsl:value-of select=”$start”/></td>
<!– code to show your additional table rows –><xsl:choose>
<xsl:when test=”number($start) < number($max)”>
<xsl:call-template name=”numbered-rows”>
<xsl:with-param name=”start” select=”number($start) + number($increment)” />
<xsl:with-param name=”increment” select=”$increment” />
<xsl:with-param name=”max” select=”$max” />
</xsl:when>
<xsl:otherwise />
</xsl:choose>
</xsl:call-template>



