punischdude
punischdude

Reputation: 219

Get the path of an element

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.

Upvotes: 0

Views: 440

Answers (2)

Erlock
Erlock

Reputation: 1968

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.

Upvotes: 2

Mike
Mike

Reputation: 314

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

Upvotes: 0

Related Questions