This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: for loop
- From: "Mitch C. Amiano" <Mitch dot Amiano at alcatel dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 10 Dec 2001 12:26:36 -0500
- Subject: Re: [xsl] for loop
- Organization: Alcatel
- References: <009801c181b5$93bdd5c0$c4c909c0@COHANA>
- Reply-to: xsl-list at lists dot mulberrytech dot com
There is no direct expression for this, but you can accomplish
the same thing using a recursive template.
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
>
<xsl:preserve-space elements="*"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="loop">
<xsl:with-param name="repeat" select="number(10)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="loop">
<xsl:param name="repeat">0</xsl:param>
<xsl:if test="number($repeat) >= 1">
Loop Iteration # <xsl:value-of select="$repeat"/>
<xsl:call-template name="loop">
<xsl:with-param name="repeat" select="$repeat - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
You may want to consider why you want a loop though.
Often, there is a structure in your input that can be
used to drive the output, and for that you just need
an XPath.
Charly wrote:
>
> Hello,
> does anyone knows how to make a loop for in xsl.
> Something more like .
>
> <xsl:loop name="i" from="1" to="10" step="1">
> $i
> </xsl:loop>
>
> Please help
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
--
Mitch.Amiano (@alcatel.com)
SW Development Engineer in C++/Java/Perl/TCL/SQL/XML/XSLT/XPath
Advance Design Process Group, Raleigh Engineering Services Alcatel
USA
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list