Divya MV
Divya MV

Reputation: 2053

Xpath inside xpath

I am trying to create an xpath for the below scenario, could you please help ?

How can i find out the value of C whose @parent is /A/B/@id, that is PQR, C may not be the immediate next node . I want to evaluate result=/A/B/@id and then give the result as input to /A/C[@parent="result"]..is it possible?

<A>
 <B id="1">W</B>
 <C parent="1">PQR</C>
 <C parent="2">ABC</C>
</A>

Upvotes: -1

Views: 57

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66714

Yes, it's possible.

With a predicate filter expression, you can test whether the @parent value of /A/C is equal to the @id value of the /A/B element and it will return the C element that satisfies that criteria.

/A/C[@parent=/A/B/@id]

Upvotes: 2

Related Questions