Reputation: 791
I want to use XPath to select the sub tree containing the <name>
-tag with "ABC" and not the other one from the following xml. Is this possible? And as a minor question, which keywords would I use to find something like that over Google (e.g. for selecting the sub tree by an attribute I would have the terminology for)?
<root>
<operation>
<name>ABC</name>
<description>Description 1</description>
</operation>
<operation>
<name>DEF</name>
<description>Description 2</description>
</operation>
</root>
Upvotes: 1
Views: 1646
Reputation: 661
For your first question, I think a more accurate way to do it would be://operation[./name[text()='ABC']]
.
And according to this , we can also make it://operation[./name[text()[.='ABC']]]
Upvotes: 1
Reputation: 243459
Use:
/*/operation[name='ABC']
For your second question: I strongly recommend not to rely on online sources (there are some that aren't so good) but to read a good book on XPath.
See some resources listed here: https://stackoverflow.com/questions/339930/any-good-xslt-tutorial-book-blog-site-online/341589#341589
Upvotes: 1