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

Re: Increment a Value in xsl:for-each

Subject: Re: Increment a Value in xsl:for-each
From: "Raj Avula" <raj_avula@xxxxxxxxxxx>
Date: Thu, 8 Mar 2001 14:15:30 -0800
xsl for each increment
Thanks jeni. It worked for me.

Raj.


----- Original Message ----- 
From: "Jeni Tennison" <mail@xxxxxxxxxxxxxxxx>
To: "Raj Avula" <raj_avula@xxxxxxxxxxx>
Cc: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, March 08, 2001 2:06 PM
Subject: Re:  Increment a Value in xsl:for-each


> Hi Raj,
> 
> > In xsl:for-each I have to read first Address and First City for the
> > first time, Second Address and second City second time and so on.
> >
> > My XSL template is
> >
> > <xsl:variable name="iCount" select="1"/>
> >
> > <xsl:for-each select="Address">
> >     <xsl:value-of select="Address"/>
> >     <xsl:value-of select=../City[position()=$iCount"/>
> > </xsl:for-each>
> >
> > I have to increment iCount in for loop.
> >
> > Can you please tell me how can I increment iCount in for-each loop.
> 
> XSLT doesn't allow you to increment variables.  There are usually
> other ways to do what you need to do, and there is in this case.
> 
> Use xsl:for-each to iterate over the Address elements and then use the
> position() of the Address to index into the City elements:
> 
>   <xsl:for-each select="Address">
>      <xsl:variable name="iCount" select="position()" />
>      <xsl:value-of select="." />
>      <xsl:value-of select="../City[$iCount]" />
>   </xsl:for-each>
> 
> Two things to note here: first, the Address element that you're
> looking at within the xsl:for-each is the current node within the
> xsl:for-each.  In your xsl:for-each, you're getting the value of the
> child Address element of the current Address element - I don't
> think you have nested Address elements, so I don't think that's what
> you wanted.
> 
> The other thing to note is that $iCount is a number, so there's no
> need to test whether the position() of the node equals it - you can
> just put the number as the value of the predicate and the nodes will
> automatically be filtered by position().
> 
> I hope that helps,
> 
> Jeni
> 
> ---
> Jeni Tennison
> http://www.jenitennison.com/
> 
> 
> 

 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.