Reputation: 125
My problem : I need to check the attribute "attributeToBeTested" of "testElement". "testElement" is the only child of "test". One condition : this "test" element must be a child of "toto" and not a child of "tata" or "titi".
So I wrote my test as :
//toto/descendant::test/descendant::testElement[attribute::attributeToBeTested != "Z"] and //test[not(ancestor::tata)] and //test[not(ancestor::titi)]
What i think i wrote : give me all "test" elements, child of "toto", where the "attributeToBeTested" of the "testElement" element is not set at "Z" AND that doesn't have "tata" or "titi" as ancestor.
But apparently, this test is wrong and this is driving me crazy !
Here is the XML example :
<tata>
....
<test>
<testElement attributeTobeTested="Z"/>
</test>
</tata>
<toto>
....
<test>
<testElement attributeTobeTested="H"/>
</test>
....
<test>
<testElement attributeTobeTested="Z"/> <---- This one should pop up
</test>
</toto>
<toto>
....
<titi>
<test>
<testElement attributeTobeTested="Z"/>
</test>
</titi>
</toto>
Only one should pop up : the one inside the "toto" not in "tata" and not in "titi" and with attribute to "Z"
Upvotes: 1
Views: 56
Reputation: 52685
Try below XPath:
//toto//test[not(ancestor::*[name()=("titi", "tata")])]/testElement[@attributeTobeTested="Z"]
It should return you required testElement
node
Upvotes: 1