I'm trying to do this:
//x[//y[@a = @b]]
I need to find all elements <x>, which have <y> somewhere in the document, such that x/@a = y/@b. Obviously, my code is wrong. How to show that @a belongs to x and @b belongs to y?
CodePudding user response:
Regarding the literal title question (How to refer to the parent in XPath?), the answer would be to use the parent:: axis or its abbreviation (..). However, that's not actually needed to achieve the requested outcome here.
This XPath,
//x[@a = //y/@b]
will select all x elements with an a attribute value that equals some y element's b attribute value anywhere in the document.
