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

AW: simple conditional looping

Subject: AW: simple conditional looping
From: <christof.hoeke@xxxxxxx>
Date: Mon, 16 Aug 2004 11:05:59 +0200
simple conditional
> Von: Keyur K [mailto:kkeyur@xxxxxxxxxxx]
> Betreff:  simple conditional looping
>
> I want to write a simple loop statement like for($i=1; $i <=
> 50; $i++) in my
> stylesheet to generate 50 tr (table rows).
>
> I am not sure how I can do this. I tried using
> <xsl:for-each/> but it just
> loops through the nodes. I cannot specifiy any conditional
> test like in
> <xsl:if /> .
>
> How can I achieve this? Pl. advice.
>
> Keyur
>

you might want to try a recursive template, something like:


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<!--
example call
	-->
	<xsl:template match="/">
		<xsl:call-template name="for-loop">
			<xsl:with-param name="i">5</xsl:with-param>
			<xsl:with-param name="stopat">20</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	<!--
forloop([i, ]stopvalue)
	-->
	<xsl:template name="for-loop">
		<xsl:param name="stopat" select="50"/>
		<xsl:param name="i" select="1"/>
		<xsl:if test="$i &lt;= $stopat">
			<!-- insert output here -->
			<xsl:value-of select="concat($i, ', ')"/>
			<!-- / -->
			<xsl:call-template name="for-loop">
				<xsl:with-param name="stopat" select="$stopat"/>
				<xsl:with-param name="i" select="$i + 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>


both params are optional. just insert the output you want at the specified
position.

chris

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.