<xslTutorial creator="nicmila@idoox.com">
<index keywords='xsl:param xsl:with-param xsl:call-template xsl:if'/>

<description>While XSLT does not define while and for loops, their behavior can be simulated. <stylesheet id='id2'/> simulates for and <stylesheet id='id3'/> while behavior. 
</description>

<xmlSource id="id1">
<AAA repeat="3"/>
<BBB repeat="2"/>
<CCC repeat="5"/>
</xmlSource>

<attValues>
<value match="">
</value>
</attValues>


<xslStylesheet id="id2">
<xsl:template match="/xslTutorial/*">
<p>
<xsl:call-template name="for">
<xsl:with-param  name="stop">
<xsl:value-of select="@repeat"/>
</xsl:with-param> 
</xsl:call-template>
</p>
</xsl:template>

<xsl:template name="for">
<xsl:param name="start">1</xsl:param>
<xsl:param name="stop">1</xsl:param>
<xsl:param name="step">1</xsl:param>

<xsl:value-of select="name()"/>
<xsl:text> </xsl:text>
 
<xsl:if test="$start < $stop">
<xsl:call-template name="for">
<xsl:with-param name="stop">
<xsl:value-of select="$stop"/>
</xsl:with-param>
<xsl:with-param name="start">
<xsl:value-of select="$start + $step"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xslStylesheet>

<xslStylesheet id="id3">
<xsl:template match="/xslTutorial/*">
<p>
<xsl:call-template name="while">
<xsl:with-param  name="test">
<xsl:value-of select="@repeat"/>
</xsl:with-param> 
</xsl:call-template>
</p>
</xsl:template>

<xsl:template name="while">
<xsl:param name="test"/>
<xsl:value-of select="name()"/>
<xsl:text> </xsl:text>

<xsl:if test="not($test = 1)">
<xsl:call-template name="while">
<xsl:with-param name="test">
<xsl:value-of select="$test - 1"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>

</xsl:template>
</xslStylesheet>
</xslTutorial>