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

using position() with XPath

Subject: using position() with XPath
From: Michael Sobczak <msobczak@xxxxxxxxx>
Date: Tue, 11 Sep 2001 06:05:23 -0700 (PDT)
xpath position
Hi,

I need to use position() to get the position of
an ancestor to the current <childMenu> node. 
Using the following xml:

<?xml version="1.0" encoding="UTF-8"?>
<menus>
	<parentMenu type="upper" title="Main Menu">
		<childMenus>
			<childMenu title="News"/>
			<childMenu title="Discussions"/>
		</childMenus>
	</parentMenu>
	<parentMenu type="lower" title="International
Menu">
		<childMenus>
			<childMenu title="Distribution"/>
			<childMenu title="World Headquarters"/>
		</childMenus>
	</parentMenu>
</menus>

I created the the following template for the
<childMenu> node:

<xsl:template match="childMenu[@title]">
	<LI><xsl:value-of
select="position(ancestor::parentMenu)"/>_<xsl:value-of
select="position()"/>. <xsl:value-of
select="@title"/></LI>
	<xsl:apply-templates/>
</xsl:template>

However, both of the position() calls return the
same value, like so:

1. Main Menu 
1_1. News 
2_2. Discussions 

2. International Menu 
1_1. Distribution 
2_2. World Headquarters 

When I change the first value-of in the template
to use "1 +
count(parent::*/preceding-sibling::*)" as
described in the FAQs, I get this:

1. Main Menu 
1_1. News 
1_2. Discussions 

2. International Menu 
1_1. Distribution 
1_2. World Headquarters 

What do I need to do to determine the position of
the current node's ancestor?


Thank you for your help,

- Mike.

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.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.