xsl-list
[Top] [All Lists]

RE: repetition

2003-05-27 11:55:23
From: abbouh [mailto:abbouh(_at_)ra(_dot_)cit(_dot_)alcatel(_dot_)fr]
Sent: Tuesday, May 27, 2003 11:10 AM
Subject: [xsl] repetition


i want to know how i can repeat an instruction in xsl
for example i want to display text "toto" n time
whithout repeating
<xsl:text>toto</xsl:text>   n time.
thanks

XSLT doesn't have procedural loop counters, but you can use recursion to get
the same effect.  At its simplest:

<xsl:template name="text-loop">
  <xsl:param name="max-times" select="1"/>
  <xsl:param name="i" select="0"/>
  <xsl:if test="$i &lt; $max-times">  
    <xsl:text>toto </xsl:text>
    <xsl:call-template name="text-loop">
      <xsl:with-param name="max-times" select="$max-times"/>
      <xsl:with-param name="i" select="$i + 1"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

Usage:

<xsl:call-template name="text-loop">
  <xsl:with-param name="max-times" select="5"/>
</xsl:call-template>

Output:

toto toto toto toto toto 

hth,
b.

|       please note new address and phone #'s effective may 19        |
| brian martinez                           
brian(_dot_)martinez(_at_)cendant(_dot_)com |
| lead gui programmer                                    303.357.3548 |
| cheap tickets, part of trip network                fax 303.357.3380 |
| 6560 greenwood plaza blvd., suite 400           englewood, co 80111 |
| cendant travel distribution services   http://www.cheaptickets.com/ |

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



<Prev in Thread] Current Thread [Next in Thread>