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

Re: xsl loop with variable

Subject: Re: xsl loop with variable
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Tue, 29 Oct 2002 10:32:13 -0000
xsl loop
Hello,

Your Stylesheet is incorrect..It should actually not work  for the reason
that you have defined two variables of the same name within one template ,
which is an error.If you are using older version of XALAN then it would
probably work and this is a bug XALAN.

> I can't make "numMonth" variable update with the correct increment out of
the "if" tag, so that "Num months:" show me the correct value (until >now
only show '0', the original value).

In XSLT you can not update a variable. once you have assigned a value to
it,the variable has this value untill it goes out of scope.

 ><xsl:if test="not($lastMonth=substring(editionDate,4,2))">
 ><xsl:variable name="numMonth" select="$numMonth+1"/>
 ></xsl:if>
You cant access this variable outside the xsl:if .. it goes out of scope.
I guess what you want to do is..
for-each listObject/object,
If the given condition satisfies, then add 1 to the value of numMonth and
store it in a variable.
you may want to try the following to do what you want to do.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <xsl:variable name="numMonth" select="1"/>
  <xsl:variable name="lastMonth" select="00"/>
  <xsl:for-each select="listObject/object">
   <xsl:variable name="numMonth1">
    <xsl:if test="not($lastMonth=substring(editionDate,4,2))">
     <xsl:value-of select="$numMonth+position()"/>
    </xsl:if>
   </xsl:variable>
   <xsl:value-of select="$numMonth1"/>
   <xsl:variable name="lastMonth1" select="substring(editionDate,4,2)"/>
   <!--<xsl:value-of select="$lastMonth1"/> -->
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

If this is not what you want,please let us know  and some one in the list
would be able to help you.
HTH
Vasu

----- Original Message -----
From: "rit7esyahoo" <rit7es@xxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, October 29, 2002 8:22 AM
Subject:  xsl loop with variable


> Hi all:
> I have the next xsl code:
>
>   <xsl:variable name="numMonth" select="0"/>
>   <xsl:variable name="lastMonth" select="00"/>
>
>   <xsl:for-each select="listObject/object">
>
> <xsl:if test="not($lastMonth=substring(editionDate,4,2))">
>   <xsl:variable name="numMonth" select="$numMonth+1"/>
> </xsl:if>
>
> Num months:<xsl:value-of select="$numMonth"/>
>
> <xsl:variable name="lastMonth" select="substring(editionDate,4,2)"/>
>
>     </xsl:for-each>
>
> I can't make "numMonth" variable update with the correct increment out of
the "if" tag, so that "Num months:" show me the correct value (until now
only show '0', the original value).
> How can i do that? Can anybody help me please?
>
> Thanks.
> _______________________________________________________________
> Yahoo! Messenger
> Nueva versión: Webcam, voz, y mucho más ¡Gratis!
> Descárgalo ya desde http://messenger.yahoo.es
>
>
>  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.