🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fr.comp.text.xml
Article #9013

Re: XSLT: équivalent du for ?

#9013
From: Thomas Broyer
Date: Fri, 22 Jun 2001 00:37
44 lines
2255 bytes
In <9gt8km$h3r$1@wanadoo.fr>, Romain Guy wrote:

>     Bonjour ! J'ai un document XML contenant l'attribut "lines" (par
> exemple: lines="20"). Comment puis-je faire l'�quivalent de:
> for(int i = 0; i < lines; i++)
>   output(i + "<br>");
> 
> dans ma feuille de style XSL ??

XSLT est un langage fonctionnel, donc utilisant, entre autres, � fond la 
r�cursivit�.

function for (int cur, int max, int increment) {
  output (cur + "<br>");
  if (cur < max)
    for (cur + increment, max, increment);
}
puis
for (0, lines, 1);
(d�sol�, j'ai pas r�vis� mon LISP...)

Soit
<xsl:template name="for">
<xsl:param name="cur" select="0"/>
<xsl:param name="max" select="0"/>
<xsl:param name="increment" select="1"/>

  <xsl:value-of select="$cur"/><br/>
  <xsl:if test="$cur < $max">
    <xsl:call-template name="for">
      <xsl:with-param name="cur" select="$cur + $increment"/>
      <xsl:with-param name="max" select="$max"/>
      <xsl:with-param name="increment" select="$increment"/>
    </xsl:call-template/>
  </xsl:if>
</xsl:template>
puis
<xsl:call-template name="for">
  <!-- cas particulier : pas besoin de passer $cur et $increment,
       les valeurs par d�faut nous conviennent -->
  <xsl:with-param name="max" select="$lines"/>
</xsl:call-param>

Tom.
Technical Details
Message-ID: <2170021.3eYUQgxmLv@ltgt.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!193.251.151.101!opentransit.net!proxad.net!feeder2-1.proxad.net!nnrp4.proxad.net.POSTED!not-for-mail
References: <9gt8km$h3r$1@wanadoo.fr>

Show Full Headers
Complete Article Headers
X-Google-Language: FRENCH,ASCII
X-Google-Thread: 114f60,9a3e87b9655eb90b
X-Google-Attributes: gid114f60,public
X-Google-ArrivalTime: 2001-06-21 17:37:19 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!193.251.151.101!opentransit.net!proxad.net!feeder2-1.proxad.net!nnrp4.proxad.net.POSTED!not-for-mail
Message-ID: <2170021.3eYUQgxmLv@ltgt.net>
From: Thomas Broyer <ptittom+news@free.fr>
Subject: Re: XSLT: équivalent du for ?
Newsgroups: fr.comp.text.xml
References: <9gt8km$h3r$1@wanadoo.fr>
Lines: 44
Organization: </>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit
Date: Fri, 22 Jun 2001 00:37:18 GMT
NNTP-Posting-Host: 217.128.160.52
X-Complaints-To: abuse@proxad.net
X-Trace: nnrp4.proxad.net 993170238 217.128.160.52 (Fri, 22 Jun 2001 02:37:18 CEST)
NNTP-Posting-Date: Fri, 22 Jun 2001 02:37:18 CEST