Does anyone know if it's possible to loop through a template and pull out node values based on an iterating number. So for example, I have the following XML strucutre:
<nodes>
<node>
<label1>Label a</label1>
<value1>Value a</value1>
<label2>Label b</label2>
<value2>Value b</value2>
<label3>Label c</label3>
<value3>Value c</value3>
etc...
</node>
</nodes>
There are always 20 label/value pairs of data. I want to output these via XSLT in a table. By looping through a template 20 times (unless there's a better way).
The code I have below works, but it won't accept a dynamic number when outputting the values (e.g.
<xsl:value-of select="$node/label$index"/>
)
Here's the code so far:
<xsl:param name="currentPage"/>
<xsl:variable name="numberOfPairs" select="20" />
<xsl:template match="/">
<table>
<xsl:call-template name="outputData">
<xsl:with-param name="node" select="$currentPage" />
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="outputData">
<xsl:param name="node" select="." />
<xsl:param name="index" select="1" />
<tr>
<td><xsl:value-of select="$node/label1"/></td>
<td><xsl:value-of select="$node/value1"/></td>
</tr>
<xsl:if test="$index <= $numberOfPairs">
<xsl:call-template name="outputData">
<xsl:with-param name="node" select="$node" />
<xsl:with-param name="index" select="$index + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
Can anyone suggest a solution to this?