Content with Style

Web Technique

XSL: Recursive template for counting up

by Pascal Opitz on November 20 2008, 11:20

Thought I'd share this with you, even though it's nothing special: A simple XSL template that recursively increments a counter, so you can do a set number of operations.


<xsl:template name="empty-score">
 <xsl:param name="target_cnt" />
 <xsl:param name="current_cnt" />

 <xsl:if test="$target_cnt > $current_cnt">
  <p>
   Target Cnt: <xsl:value-of select="$target_cnt" />
   Current Cnt: <xsl:value-of select="$current_cnt" />
  </p>

  <xsl:call-template name="empty-score">
   <xsl:with-param name="target_cnt" select="$target_cnt" />
   <xsl:with-param name="current_cnt" select="$current_cnt + 1" />
  </xsl:call-template>
 </xsl:if>
</xsl:template>