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

Re: Repeating something "n" times.

Subject: Re: Repeating something "n" times.
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 08 Nov 2000 14:57:31 +0000
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() &lt;= $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() &lt;= $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@xxxxxxxxxxxxxxxx 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



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.