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



Hallo,
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:
/root[1]/element1[3]/subelement[2]/sub[3]

I can generate the path with names of element but there is a trouble with
position().
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()"/>]/
	</xsl:for-each>

Then the position() makes 'counter' - it always writes:
/root[1]/element[2]/subelement[3]/sub[4]
(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>
	<xsl:template match="/" mode="path"/>

Now, the position() returns always 1, so It write:
/root[1]/element[1]/subelement[1]/sub[1]
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]