I'm trying to test if an attribute on an ancestor of an element not equal a string.
Here is my XML...
<aaa att="xyz">
<bbb>
<ccc/>
</bbb>
</aaa>
<aaa att="mno">
<bbb>
<ccc/>
</bbb>
</aaa>
If I'm acting on element ccc, I'm trying to test that its grandparent aaa @att doesn't equal "xyz".
I currently have this...
ancestor::aaa[not(contains(@att, 'xyz'))]
Thanks!
Assuming that by saying an ancestor of an element you're referring to an element with child elements, this XPath expression should do:
//*[*/ccc][@att != 'xyz']
It selects
<ccc>
grandchild nodeatt
attribute whose value is not xyz
.Update: Restricted test to grandparents of <ccc>
.
Update 2: Adapted to your revised question:
//ccc[../parent::aaa/@att != 'xyz']
Selects
<ccc>
elements<aaa>
with its attribute att
set to a value that is not xyz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With