Guest RetawGnirps Posted August 6, 2009 Share Posted August 6, 2009 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 More sharing options...
boen_robot Posted August 6, 2009 Share Posted August 6, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.