[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Repeating something "n" times.
I like recursion too, but it's true it can be ungainly. To get back to
Robert's original question
How do I repeat something 'n' times without a node list with n elements? Take a node list with more than n elements and use [position() <= $n].... <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="elements" select="//*"/> <xsl:param name="times" select="0"/> <xsl:template match="/"> <xsl:call-template name="breaks"> <xsl:with-param name="times" select="$times"/> </xsl:call-template> </xsl:template> <xsl:template name="breaks"> <xsl:param name="times" select="$times"/> <xsl:for-each select="$elements[position() <= $times]"> <br/> </xsl:for-each> </xsl:template> </xsl:stylesheet> Note that in the real case you don't need the extra overhead of that top-level declaration for $times (this is just for testing). Cheers, Wendell At 06:23 PM 11/6/00 -0700, Mike Brown wrote: [When XSLT 1.1 provides node-set casting] it will also be possible to create the equivalent of arrays and hashes. That will be fun.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|