[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
news:004401c3e057$f6095850$0200a8c0@xxxxxxxxxxx
> 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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:myMultiplyby3="f:myMultiplyby3"
 exclude-result-prefixes="xsl myMultiplyby3">

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

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

  <myMultiplyby3:myMultiplyby3/>

  <xsl:template match="/">

   <xsl:variable name="vMultBy3"
select="document('')/*/myMultiplyby3:*[1]"/>

    <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:call-template>
  </xsl:template>

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

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

</xsl:stylesheet>

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


Cheers,

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