Jump to content

Param Not Incrementing


Guest RetawGnirps
 Share

Recommended Posts

Guest RetawGnirps

Hello,I am currently trying to use the code below to increment the currentChild after every iteration. However, in the output shown below, it is apparent that the value is never changing.There are four children in this example, so it is printing out the statements the correct number of times, just not incrementing the value.What can I do to keep track of the currentChild count?Thanks.Code:<xsl:param name="currentChild">0</xsl:param><xsl:for-each select="Attribute[./@name=Children.Name]/Value"> <xsl:value-of select="$currentChild"/> before increment<br/> <xsl:with-param name="currentChild" select="$currentChild+1"/> <xsl:value-of select="$currentChild"/> after increment<br/></xsl:for-each>Output:0 before increment0 after increment0 before increment0 after increment0 before increment0 after increment0 before increment0 after increment

Link to comment
Share on other sites

I'm surprised it even works without errors. xsl:with-param is only valid as a child of xsl:call-template and xsl:apply-templates.That said, you need to encompass your process in a template that you call recursively, like:

<xsl:template name="current"><xsl:param name="currentChild">0</xsl:param><xsl:value-of select="$currentChild" /><xsl:if test="number($currentChild) < 4"><!--You could get the actual number (instead of hardcoding it to 4) by various means, like count() for example--><xsl:call-template name="current"><xsl:with-param name="$currentChild" select="number($currentChild)+1" /></xsl:call-template></xsl:if></xsl:template>

Then from from another place:

<xsl:template match="/"><xsl:call-template name="current" /></xsl:template>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...