For loop in XSLT

Submitted by:David Villa

Date added:03 August, 2011

Category:XSLT

By the below template we can make for-loop using xslt.

Tags: loop in xslt

Code Snippet:

    <xsl:template name="for.loop">  
<!-- for loop templates starts here-->

<!-- for loop index variable-->
<xsl:param name="i" />

<!-- for loop end variable-->
<xsl:param name="count" />

<!--begin_: Line_by_Line_Output -->
<xsl:if test="$i <= $count">
<!-- This $i variable gives the increment value -->
<xsl:value-of select="$i"/>
</xsl:if>

<!--begin_: RepeatTheLoopUntilFinished-->
<xsl:if test="$i <= $count">
<xsl:call-template name="for.loop">
<xsl:with-param name="i">
<xsl:value-of select="$i + 1"/>
</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="$count"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
 
 

Comments