[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] AW: simple conditional looping
> 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 <= $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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|