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

RE: displaying position of nodes

Subject: RE: displaying position of nodes
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Thu, 20 Feb 2003 17:20:59 -0500
displaying nested nodes in xml
[Mac Martine]

> I'm trying to loop through all the nodes and display the 
> position of the node next to the value of the node. The 
> values display, but only one of the positions displays. Why 
> is that??? 

Because your template is only getting called once - on the document
element (/).  You are getting the "string value" of the root element
(the first child of the document element), and displaying its position()
value, which is 1.  If you want to get more (but unknown) levels of
nested elements you need to use some kind of recursion.

You may be thinking of something like this -

<xsl:template match="*">
	<xsl:value-of select="name()"/> (<xsl:value-of
select='text()'/>) 
	==<xsl:value-of select="position()"/>== <br/>
	<xsl:apply-templates select='*'/>
</xsl:template>

I put in the "<br/>" element just to get a more readable display in
Internet Explorer - tinker with the format as you like. 

Notice that position() gives you the position of an element relative to
the top of the subtree it is in when matched by a template, and not
necessarily the element count as you might have been expecting.

Cheers,

Tom P



 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.