Does anyone know if it is possible to scroll the pattern and pull out the node values based on the iteration number. So, for example, I have the following XML file:
<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 pairs of label / value data. I want to output them through XSLT in a table. By scrolling the template 20 times (if there is no better way).
The code that I have below works, but it does not accept a dynamic number when outputting values (for example,
<xsl:value-of select="$node/label$index"/>
)
Here is the code:
<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?
source share