[xsl] implement for loop with XSLT

Subject: [xsl] implement for loop with XSLT
From: Tobias Reif <tobiasreif@xxxxxxxxx>
Date: Tue, 27 Mar 2001 06:45:07 -0800 (PST)
Dan Diebolt <dandiebolt@xxxxxxxxx> wrote on
http://www.biglist.com/cgi-bin/wilma/wilma_hiliter/xsl-list/200103/msg01009.html
:

> I came up with the enclosed code to grab the value
of > an <n> element
> and generate a list of integers and their squares >
between 1 and n:
> 
>    1 1
>    2 4
>    3 9
>    ...
>    8 64
>    9 81
>    10 100
> 
> I am a bit stunned at how intricate this code looks.
> Is there
> a more direct way to accomplish this?

try

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="text" encoding="UTF-8"/>
	<xsl:template match="/" name="square">
		<xsl:param name="range" select="100"/>
		<xsl:param name="current" select="1"/>
<xsl:value-of select="$current"/> &#42; <xsl:value-of
select="$current"/> &#61; <xsl:value-of
select="$current * $current"/>
		<xsl:text>
</xsl:text>
		<xsl:if test="$current &lt; $range">
			<xsl:call-template name="square">
				<xsl:with-param name="current"
select="$current+1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>


Tobi

=====
Tobias Reif
http://www.pinkjuice.com/myDigitalProfile.htm

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/?.refer=text

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread