Subject: Re: [xsl] Using a parameter in a select within a recursive template From: "M. David Peterson" <m.david@xxxxxxxxxx> Date: Sun, 19 Sep 2004 00:31:07 -0700 |
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <xsl:call-template name="adddata"> <xsl:with-param name="number" select="'5'"/> <xsl:with-param name="cols" select="'0'"/> </xsl:call-template> </xsl:template>
<xsl:template name="adddata"> <xsl:param name="number"/> <xsl:param name="cols"/>
<xsl:choose> <xsl:when test="$number >= $cols"> <xsl:value-of select="//*[local-name() = concat('FIELD_',$number)]"/> <xsl:call-template name="adddata"> <xsl:with-param name="number" select="$number - 1"/> <xsl:with-param name="cols" select="$cols" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$cols"/> </xsl:otherwise> </xsl:choose>
</xsl:template> </xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?> <fields> <FIELD_1>test of field 1</FIELD_1> <FIELD_2>test of field 2</FIELD_2> <FIELD_3>test of field 3</FIELD_3> <FIELD_4>test of field 4</FIELD_4> <FIELD_5>test of field 5</FIELD_5> </fields>
Hi everyone, I am attempting to use a parameter within a recursive template to select a different node whenever the template loops.
My datafile looks something like this:
<FIELD_1> <FIELD_2> <FIELD_3> <FIELD_4> <FIELD_5> ... <FIELD_142>
I would like to loop through and use the incremented parameter to select the contents of the node. So far I have been trying to use this template:
<xsl:template name="adddata"> <xsl:param name="number" select="141" /> <xsl:param name="cols" select="19" />
<xsl:choose> <xsl:when test="$number <= $cols"> <xsl:value-of select="cols"/> </xsl:when> <xsl:otherwise> <xsl:call-template name="adddata"> <xsl:with-param name="number" select="$number - 1"/> <xsl:with-param name="cols" select="$cols" /> </xsl:call-template> <fo:table-cell > <fo:block><xsl:value-of select="concat('FIELD_',$number)" /></fo:block> </fo:table-cell> </xsl:otherwise> </xsl:choose> </xsl:template>
However, the output gives me: FIELD_1 FIELD_2 FIELD_3 etc.... rather than the data contained within these nodes. Can someone shed some light for me?
TIA, Helen.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Using a parameter in a se, J.Pietschmann | Thread | Re: [xsl] Using a parameter in a se, Josh Canfield |
Re: [xsl] Using a parameter in a se, J.Pietschmann | Date | Re: [xsl] translate and templates a, J.Pietschmann |
Month |