[xslt] Creating absolute XPath path to the node - problem with position()

I have one trouble with libxslt: I need to write the absolute XPath to the
current element and I need positions of elements. For example I need to obatin
the absolute XPath path if I'm in the element 'sub' which may be:

I can generate the path with names of element but there is a trouble with
If I try something as (both examples are simplified):

	<!-- <xsl:text> tags are not here for lucidity -->
	<xsl:for-each select="ancestor-or-self::*">
		<xsl:value-of select="local-name()"/>
		[<xsl:value-of select="position()"/>]/

Then the position() makes 'counter' - it always writes:
(It is in the general case: /element1[1]/element2[2]/element3[3]/...)

So I can to eliminate the for-each cycle and I try:

	<xsl:template match="node()" mode="path">
		<xsl:apply-templates select=".." mode="path"/>
		<xsl:value-of select="local-name()"/>
		[<xsl:value-of select="position()"/>]/
	<xsl:template match="/" mode="path"/>

Now, the position() returns always 1, so It write:
I tested it and this template walks over good elements (I distinguished it by
the attribute).

So, what's wrong? Is it the bug or feature? And if it is a feature, how can I
obtain the absolute XPath with positions to the current element?

Have a nice day

Petr Novak

Petr Novak, Liberouter Project (www.liberouter.org)
E-mail: novak liberouter org, novak merlot ics muni cz

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]