[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:variable

Subject: Re: xsl:variable
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Thu, 6 Mar 2003 20:12:22 +0100
xslt variable counter
> i would like to write something like this :
>
> <xsl:variable name="counter" select="0"/>
> <xsl:for-each select="toto">
>     <xsl:variable name="counter" select="$counter+1"/>
> </xsl:for-each>
>
> i know that i'm wrong but how could i do that?

You cannot increment (or modify in any way) the assigned value of an
xsl:variable, because xslt is a functional language.

However you could do:

  <xsl:for-each select="toto">
      <xsl:variable name="someName" select="position()"/>
  </xsl:for-each>

Note also, that the "someName" variable goes out of scope outside the body
of the xsl:for-each element.

As per the current draft of XSLT 2.0 the code proposed by you will not raise
an error! ... but it will not do at all what you're expecting -- the value
of $counter inside the body of xsl:for-each will always be 1.


Hope this helped.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL



"Laurence Mossuz" <mossuz@xxxxxxxxxxxxx> wrote in message
news:3E6776DF.5CE65BC8@xxxxxxxxxxxxxxxx
> hello
>
> i would like to declare a variable counter in my xsl file and to
> incremente it whenever i have the occurence toto in my XML file.
> toto is a complextype whose maxOccurs="unbounded" in the schema
> declaration.
> For instance we can have in the xml file :
> <test>
>     <toto>
>       <titi/>
>       <tata/>
>     </toto>
>     <toto>
>      <titi>hello</titi>
>       <tata>bye</tata>
>     </toto>
> </test>
>
> i would like to write something like this :
>
> <xsl:variable name="counter" select="0"/>
> <xsl:for-each select="toto">
>     <xsl:variable name="counter" select="$counter+1"/>
> </xsl:for-each>
>
> i know that i'm wrong but how could i do that?
>
> Many thanks for your help!!
>
> Lo.
> --
>
> Laurence MOSSUZ
>
> LAPP Service Informatique
> Chemin de Bellevue BP 110
> 74941 Annecy-Le-Vieux CEDEX
> Tel : 04 50 09 17 31 _ Fax : 04 50 27 94 95
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>




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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.