user764357
user764357

Reputation:

Compare attribute of one element to attribute of another element

This seems like it should be easy, but I can never figure it out.

Presume I have the following document:

<data>
    <a>
       <b val="1"/>
    </a>
    <c val="1">
</data>

And assume that I am executing an XPath from the context of <b>. I need to check if there is an element c that has the same value as b.

Obviously, this doesn't work:

../a/c[@val=@val]

How to I get an XPath to remember its "current" context when traversing the tree?

Upvotes: 0

Views: 105

Answers (1)

user142162
user142162

Reputation:

Try the expression below. You'll notice that the current node is not lost since a predicate is used for finding the c node.

.[../../c/@val=@val]

Upvotes: 3

Related Questions