Subject: AW: [xsl] simple conditional looping From: <christof.hoeke@xxxxxxx> Date: Mon, 16 Aug 2004 11:05:59 +0200 |
> Von: Keyur K [mailto:kkeyur@xxxxxxxxxxx] > Betreff: [xsl] 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 <= $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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] simple conditional loopin, David Carlisle | Thread | AW: [xsl] simple conditional loopin, christof.hoeke |
Re: [xsl] simple conditional loopin, Mukul Gandhi | Date | Re: [xsl] Problems generating w-cir, David Carlisle |
Month |