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

RE: Linear counting problem in nested loop.

Subject: RE: Linear counting problem in nested loop.
From: kakridge@xxxxxxxxxxxxx
Date: Thu, 22 Jan 2004 10:25:35 -0500
RE:  Linear counting problem in nested loop.
Just to be clear, you cannot take the value before the iteration, like
this:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="MENU">
	<xsl:variable name="total" select="count(MenuItems) +
count(*/SubMenuItems)"/>
	<xsl:value-of select="$total"/>

</xsl:template>
</xsl:stylesheet>



-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Govil, Anoop
(Contractor)
Sent: Thursday, January 22, 2004 9:34 AM
To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
Subject:  Linear counting problem in nested loop.

Hi,
I have the following XML and want to implement such that I can have a
linear
counter increment with each iteration of the parent for-each loop and
also
the nested for-each loop. 
<?xml version="1.0"?>
<MENU>
    <MenuItems>
        <MenuLabel>Menu 1</MenuLabel>
        <SubMenuItems>
            <SubMenuLabel>Sub Menu 1</SubMenuLabel>
        </SubMenuItems>
        <SubMenuItems>
            <SubMenuLabel>Sub Menu 11</SubMenuLabel>
        </SubMenuItems>
    </MenuItems>
    <MenuItems>
        <MenuLabel>Menu 2</MenuLabel>
        <SubMenuItems>
            <SubMenuLabel>Sub Menu 2</SubMenuLabel>
        </SubMenuItems>
    </MenuItems>
</MENU>
e.g. The counter should return as: 
1 for Menu 1
2 for SubMenu 1
3 for SubMenu 11
4 for Menu 2
5 for SubMenu 2
So far, what I got is the counter breaks when it reaches the second
<MenuItems>, as it doesn't know about the subMenu from the first
MenuItems
counted 3 already... So the output of my code is something like this:
1 for Menu 1
2 for SubMenu 1
3 for SubMenu 11
2 for Menu 2
3 for SubMenu 2
Any help in fixing this will be much appreciated. Thanks a lot!

Anoop

 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.