Reputation: 81
Suppose I have a XML like this:
<my-parent-tag attr="">
<my-child-tag/>
</my-parent-tag>
<my-child-tag/> <!--I don't want to select this one-->
I want to find all my-child-tags that have the parent node my-parent-tag with attr="". How do I express this in Xpath? I tried
//my-child-tag and [../my-parent-tag[@attr='']]
But, I ended up getting Xpath-no-node-selected feedback. Help appreciated :)
Upvotes: 0
Views: 94
Reputation: 4173
Why not just use regular expression //parent/child
Selects all descendant tags from parent with attribute:
//my-parent-tag[@attr='']//my-child-tag
Selects all child tags from parent with attribute:
//my-parent-tag[@attr='']/my-child-tag
Upvotes: 2
Reputation: 111678
This XPath,
//my-parent-tag[@attr='']/my-child-tag
will select all my-child-tag
elements with a parent of my-parent-tag
that has a attr
attribute value of ''
.
Upvotes: 0
Reputation: 1816
You can use //my-child-tag[parent::my-parent-tag[@attr='']]
Upvotes: 0