This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
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.
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list