RE: [xsl] for loop

Subject: RE: [xsl] for loop
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Thu, 18 Oct 2001 10:04:12 +0100
> I have one node that holds a value of say 5 (this number
> could be any number
> 1-5 ).  I need to take that value and create 5 links that
> point to different
> locations.  Since the for-each is only a iterator across node
> sets, how
> would I handle this.

Assuming your number is in $number, the usual trick solution is

<xsl:for-each select="//node()[position() &lt;= $number]">
  <link/>
</xsl:for-each>

If you don't like that, the longwinded solution is a recursive named
template that takes $number as a parameter, outputs one link, and then calls
itself with the parameter set to ($number - 1), terminating when it reaches
zero.

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread