RE: [xsl] displaying position of nodes

Subject: RE: [xsl] displaying position of nodes
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Thu, 20 Feb 2003 17:20:59 -0500
[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