Xslt For loop example

08/12/2012 11:53

<?xml version="1.0" encoding="utf-8"?>

<!-- Edited by Lukas Sevcik® -->

    <xsl:stylesheet version="1.0"

    xmlns:xsl="https://www.w3.org/1999/XSL/Transform">

        <xsl:template match="/">

            <html>

                <body>

                    <h2>For loop Example</h2>

                    <xsl:call-template name="forLoop">

                        <xsl:with-param name="max">5</xsl:with-param>

                        <xsl:with-param name="i">1</xsl:with-param>

                    </xsl:call-template>

                </body>

            </html>

        </xsl:template>

 

        <xsl:template name="forLoop">

            <xsl:param name="max"/>

            <xsl:param name="i"/>

            <xsl:if test="not($i &gt; $max)">

                <xsl:value-of select="$i"/>,

                <xsl:call-template name="forLoop">

                    <xsl:with-param name="max"><xsl:value-of select="$max"/></xsl:with-param>

                    <xsl:with-param name="i"><xsl:value-of select="$i+1"/></xsl:with-param>

                </xsl:call-template>

             </xsl:if>

        </xsl:template>

</xsl:stylesheet>