Subject: RE: [xsl] increment value - philosophy From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sun, 08 Feb 2004 16:56:44 -0500 |
Thanks for your solution. I tested it in my application. I have a new issue with this solution, if one of the sub menu items is empty (i.e., the SubMenuLabel tag is empty), it still counts it and doesn't skip that if it is empty. I tried various things but still can't skip it. I will really appreciate if you think of how to fix that issue to skip a submenuitem node if it is empty.
t:\ftemp>type snoop.xml <?xml version="1.0"?> <MENU> <MenuItems> <MenuLabel>Menu 1</MenuLabel> <SubMenuItems> <SubMenuLabel>Sub Menu 1</SubMenuLabel> </SubMenuItems> <SubMenuItems> <SubMenuLabel></SubMenuLabel> </SubMenuItems> <SubMenuItems> <SubMenuLabel>Sub Menu 11</SubMenuLabel> </SubMenuItems> </MenuItems> <MenuItems> <MenuLabel>Menu 2</MenuLabel> <SubMenuItems> <SubMenuLabel></SubMenuLabel> </SubMenuItems> <SubMenuItems> <SubMenuLabel>Sub Menu 2</SubMenuLabel> </SubMenuItems> </MenuItems> </MENU>
t:\ftemp>type snoop.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[node()]"> <xsl:value-of select="1 + count(preceding::MenuLabel) + count(preceding::SubMenuLabel[node()])"/> <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[node()]"> <xsl:number level="any" count="MenuLabel | SubMenuLabel[node()]"/> <xsl:value-of select="concat(' ',.)"/><xsl:text> </xsl:text> </xsl:for-each> </xsl:template>
t:\ftemp>saxon snoop.xml snoop.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: upcoming world tour of hands-on XSL training events Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO Washington, DC: 2004-03-15 San Francisco, CA: 2004-03-22 Hong Kong: 2004-05-17 Germany: 2004-05-24 England: 2004-06-07 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, Govil, Anoop (Contra | Thread | RE: [xsl] increment value - philoso, Govil, Anoop (Contra |
RE: [xsl] increment value - philoso, Govil, Anoop (Contra | Date | [xsl] documenting xsl stylesheets, Paul Tremblay |
Month |