Reputation: 73
Using Xpath, how can I locate a parent element where none of multiple child elements contains a specific attribute value among a list of attribute values?
Here's a sample of my xml:
<app>
<rdg wit="#R #W #I #S #C #O #D">existunt,</rdg>
<rdg wit="#J">existant,</rdg>
</app>
My XML has hundreds of these elements that should all have the same set of eight attribute values (#R, etc.) distributed variously among two or more elements. But a few of the are missing an attribute value on the list, and I need to locate those nodes.
So I'm trying to find, say, all the <app>
elements where none of the child <rdg>
elements contains #R.
I can get the ones that do contain #R with //app/rdg[contains(@wit,"#R")]
and I know there's a not() function, but I haven't figured out how to get these to work together.
Upvotes: 3
Views: 535
Reputation: 101700
You can accomplish this as follows:
//app[not(rdg/@wit[contains(., '#R')])]
Alternatively:
//app[not(rdg[contains(@wit, '#R')])]
This slightly convoluted approach is necessary because the app
s contain multiple rdg
s, so we're basically doing (to take the second example):
app
s where...rdg
child where...wit
attribute contains #R
Upvotes: 3