XSLT For Loop

If you ever need to implement a for loop in XSLT, here’s one possibility:

   1: <xsl:template name="for">
   2:     <xsl:param name="from"/>
   3:     <xsl:param name="to"/>
   5:     <xsl:if test="$from &lt;= $to">
   6:         <xsl:variable name="newfrom" select="$from+1"/>
   8:         Here I am! <xsl:value-of select="$from"/>
  10:         <xsl:call-template name="for">
  11:             <xsl:with-param name="from" select="$newfrom"/>
  12:             <xsl:with-param name="to" select="$to"/>
  13:         </xsl:call-template>
  14:     </xsl:if>
  15: </xsl:template>


No Comments

Add a Comment

As it will appear on the website

Not displayed

Your website