Subject: RE: [xsl] increment value - philosophy From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 22 Jan 2004 15:06:35 -0500 |
Thanks for your note. That put things into the right perspective.
Yes, you are true that we are trying to get too much out of XSL.
My problem is due to two nested loops and the position() value is different in these two loops.
I have started looking into recursive template implementation to find a solution to my problem there.
If you have any sample for that, it will definitely be helpful to start with.
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
T:\ftemp>type anoop.xml <?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>
T:\ftemp>type anoop.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <xsl:text>Method 1: using the count function: </xsl:text> <xsl:for-each select="//MenuLabel | //SubMenuLabel"> <xsl:value-of select="1 + count(preceding::MenuLabel) + count(preceding::SubMenuLabel)"/> <xsl:value-of select="concat(' ',.)"/><xsl:text> </xsl:text> </xsl:for-each> <xsl:text>Method 2: using xsl:number: </xsl:text> <xsl:for-each select="//MenuLabel | //SubMenuLabel"> <xsl:number level="any" count="MenuLabel | SubMenuLabel"/> <xsl:value-of select="concat(' ',.)"/><xsl:text> </xsl:text> </xsl:for-each> </xsl:template>
</xsl:stylesheet> T:\ftemp>saxon anoop.xml anoop.xsl Method 1: using the count function: 1 Menu 1 2 Sub Menu 1 3 Sub Menu 11 4 Menu 2 5 Sub Menu 2 Method 2: using xsl:number: 1 Menu 1 2 Sub Menu 1 3 Sub Menu 11 4 Menu 2 5 Sub Menu 2
-- Public courses: sign up for one or both soon to reserve your seat! Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO Washington, DC: 2004-03-15 San Francisco, CA: 2004-03-22 Hong Kong, China: 2004-05-17 Bremen, Germany: 2004-05-24 World-wide on-site corporate, government & user group XML training
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] increment value - philoso, Wendell Piez | Thread | RE: [xsl] increment value - philoso, Strolia-Davis Christ |
Re: [xsl] Node-sets using <xsl:with, Mir Farooq Ali | Date | RE: [xsl] XSLT version 2.0 support , Michael Kay |
Month |