tags:

views:

70

answers:

2

Hi folks,

is there a XPath function, which returns the absolute path of an element, so I can use it in sth. like:

<xsl:if test="path() = /root/parent/child">
   ...
</xsl:if>

Thanks.

A: 

No, there isn't, but such expression '. = /root/parent/child' returns boolean and means the same.

mikesub
but you may use @match of xsl:template to select node you need, more precisely.
mikesub
No, it doesn't mean the same; with this XPath expression you check the egality of the text content of both nodes, not their identity.
Erlock
hmm, my mistake. you're right.
mikesub
+2  A: 

If you want to test if two nodes are the same, you must use generate-id():

<xsl:if test="generate-id(.) = generate-id(/root/parent/child)">
   <!-- The current node is the same as /root/parent/child -->
   ...
</xsl:if>

generate-id() returns an unique ID for each node of the document.

Erlock
I want to test if a node has an ancestor (to be detailed: the parent of the parent of the node) with a specific name. These nodes match with another template, but they should not.I fixed it now with proper match statements. Thanks, though.
To solve this problem punischdude had to write the proper path thats it .. But @Erlok has given Good idea .. anyways .. I din't know about generate-id(.) ..
infant programmer