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

Re: how to change variable values ?

Subject: Re: how to change variable values ?
From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 19 Jul 2000 14:49:22 +0200 (MET DST)
xslt change variable value
Hi Gero,

> i got the following problem: i want to output a xml-document with a 
> xsl-stylesheet. In this output it should, for example, make a line when 
> the week changes. I tried to do this by using variables...
> 
> -------------
> <xsl:variable name="lastweek">
>   <!-- Need an Initial value to compare later with currentweek-->
>   <xsl:value-of select="Week"/>  
>   <!-- Week is a tag from the xml-document -->
> </xsl:variable>
> 
> <xsl:for-each select="Data/Block">
> 
>   <xsl:variable name="currentweek">
>     <xsl:value-of select="Week"/> 
>   </xsl:variable>
> 
>   <xsl:if test="$currentweek > $lastweek">
>     <!-- Do something when week changes and set
>          the variable lastweek to this week -->
>     <xsl:variable name="lastweek">   <!-- foo ;-) -->
>       <xsl:value-of select="$currentweek">
>     </xsl:variable>
>   </xsl:if>
>   
>   .
>   .
>   .
> </xsl:for-each>
> --------------------------
> 
> Obviously, it complains, that the variable lastweek cannot be defined 
> twice. Is there a way to "just change" the variable lastweek (and not 
> to define it again) ?

The only way to use variables with changing values is by recursion.
I.e. you define a named template and call it with passing your node-set
"Data/Block" and an initial lastweek value through parameters.
The template processes the first node and calls itself recursively
with all nodes but the first and a maybe updated lastweek parameter.

If you like, you may take a look at my "XSLT loop compiler" which allows
defining iterative loops and translating them into pure XSLT.
http://www.informatik.hu-berlin.de/~obecker/XSLT/#loop-compiler

However, I think your problem can be solved much simpler:
What about

  <xsl:if test="Week > preceding-sibling::Week">
    <!-- Do something when week changes -->
  </xsl:if>

Best regards,
Oliver


/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@xxxxxxxxxxxxxxxxxxxxxxx             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/


 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.