[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

implement for loop with XSLT

Subject: implement for loop with XSLT
From: Tobias Reif <tobiasreif@xxxxxxxxx>
Date: Tue, 27 Mar 2001 06:45:07 -0800 (PST)
xsl loop range
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.