ancestor::foo[bar[@attr="val"]]
I thought this would work, but it's not. I need to find the nearest foo
element going up in the tree that has a bar
child element, which in turn has an attr
attribute of val
.
ancestor::foo[bar[@attr="val"]]
I thought this would work, but it's not. I need to find the nearest foo
element going up in the tree that has a bar
child element, which in turn has an attr
attribute of val
.
This should work:
//*[ancestor::foo[bar[@attr="val"]]]
or alternatively
root/foo/bar[ancestor::foo[bar[@attr="val"]]]
matches the second <bar>
element
<root>
<foo>
<bar attr="xxx"></bar>
</foo>
<foo>
<bar attr="val"></bar>
</foo>
<foo>
<bar attr="zzz"></bar>
</foo>
</root>