|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: increment value - philosophy
At 2004-02-08 16:28 -0500, Govil, Anoop (Contractor) wrote:
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. Rather than think about what you are skipping, try to focus on what you are counting: you are counting those SubMenuLabel elements that are not empty. When is an element not empty? When it has node children. So, only deal with SubMenuLabel[node()] elements. Again, the idea when working with the hierarchy is to let XSLT do the heavy lifting by describing what it is you want done. I hope this helps. ....................... Ken 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:output method="text"/> <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></xsl:stylesheet>
t:\ftemp>
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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








