[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Re: for-eaching for specified number of times

Subject: [xsl] Re: for-eaching for specified number of times
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Thu, 22 Jan 2004 06:55:28 +0100

"Mark Williams" <mark@xxxxxxxxxxx> wrote in message
> Hi,
> Is there a way of terminating a for-each loop after it has reached a
> specified number of iterations.

Use the "iter" template from FXSL. You don't need to worry whether you have
some big quantity of nodes.

Here's a small example:

<xsl:stylesheet version="1.0"
 exclude-result-prefixes="xsl myMultiplyby3">

 <xsl:import href="itersimple.xsl"/>

 <xsl:output omit-xml-declaration="yes"/>


  <xsl:template match="/">

   <xsl:variable name="vMultBy3"

    <xsl:call-template name="iter">
      <xsl:with-param name="pTimes" select="4"/>
      <xsl:with-param name="pFun" select="$vMultBy3"/>
      <xsl:with-param name="pX" select="1"/>

  <xsl:template match="myMultiplyby3:*">
    <xsl:param name="arg1"/>

    <xsl:value-of select="3 * $arg1"/>


This (when applied on arbitrary source.xml) will multiply a number (3 in ths
case) 3 times with itself.


Dimitre Novatchev.
FXSL developer

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html

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

Current Thread