DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
ForLoop: A Simple For Loop In Xslt
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
### begin_: file metadata
### <region-file_info>
### main:
### - name : ForLoop: a simple for loop in xslt
### desc : |
### Do a simple for loop in xslt displaying hello world.
### Call this from any source xml file.
### It works independently of the data in the xml.
### date : created="Thu 2005-12-01 11:30:52"
### last : lastmod="Thu 2005-12-01 11:30:57"
### lang : xslt
### tags : xml xslt loop for hello_world
### </region-file_info>
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head><title>Say Hello Ten Times!</title></head>
<body>
<b>I am going to say hello Ten Times!</b>
<!-- begin_: Send_Loop_To_HTML -->
<xsl:call-template name="for.loop">
<xsl:with-param name="i">1</xsl:with-param>
<xsl:with-param name="count">10</xsl:with-param>
</xsl:call-template>
</body>
</html>
</xsl:template>
<!--begin_: Define_The_Output_Loop -->
<xsl:template name="for.loop">
<xsl:param name="i" />
<xsl:param name="count" />
<!--begin_: Line_by_Line_Output -->
<xsl:if test="$i <= $count">
<br /> <b><xsl:value-of select="$i" />.</b>Hello world!
</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>
</xsl:stylesheet>





