| 
 
Subject: RE: [xsl] !!!counters in XSL!!! From: "Ignacio J. Ortega" <nacho@xxxxxxxx> Date: Thu, 5 Apr 2001 11:36:25 +0200  | 
> can anyone please tell me whether you can have counters in 
> XSL? I mean I
> want to increment a variable each time I go into a certain 
> for-each loop.
> 
Hola a todos, Rosa:
Some time ago i've developed a way to do simple interations with no
recursivity, only valid for short numbers of iterations  useful for  i.e
months..
This can be easily modified to do a bunch of other things..
You can use a external generated document for big interations, but it's
not very performant, i think, 2 parses...
Perhaps somebody finds that useful..( at least it's usefull for me :)
My 0.02 ? ( nothing compared to the income i've got from the xsl-list :)
Saludos ,
Ignacio J. Ortega
PS.:( this adapted from my code, i've not tested it , sorry if it
contains any errors )
8<--------------------------------------------------------------------
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:d="data"
>
<xsl:output method="text" indent="no" encoding="ISO-8859-1" />
  <!-- data for the transform -->
  <!-- adding d:item elemnts varies the counter -->
  <!-- you can use the index value for something -->
  <d:counter>
    <d:item>1</d:item>
    <d:item>2</d:item>
    <d:item>3</d:item>
    <d:item>4</d:item>
  </d:counter>
  <xsl:template match="/">
    <fourtimesoriginaltree>
    <xsl:variable name="backptr" select="."/>
    <xsl:for-each select="document('')//d:counter/d:item">
        <!--- Output some elements or do some iterative work -->
        <!-- use backptr for the original context tree       -->
        <!-- the example copies the source tree 4 times to the output
tree -->
        <originaltree copy="{.}">
            <xsl:copy-of select="$backptr"/>
        </originaltree>    
    </xsl:for-each>
    </fourtimesoriginaltree>
  </xsl:template>  
</xsl:stylesheet>
8<--------------------------------------------------------------------
 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| Current Thread | 
|---|
  | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] !!!counters in XSL!!!, David Carlisle | Thread | Re: [xsl] !!!counters in XSL!!!, Trevor Nash | 
| [xsl] Built in templates, Richard Mitchell | Date | RE: [xsl] XSL vs. JSP, Nick Vincent | 
| Month |