The XPath bookstore/book[1]
selects the first book node under bookstore
.
How can I select the first node that matches a more complicated condition, e.g. the first node that matches /bookstore/book[@location='US']
The key part of this XPath is *[1] , which will select the node value of the first child of Department .
To open the Find function, use the shortcut Ctrl+F or navigate to Home>Editing>Find.
Use:
(/bookstore/book[@location='US'])[1]
This will first get the book elements with the location attribute equal to 'US'. Then it will select the first node from that set. Note the use of parentheses, which are required by some implementations.
Note, this is not the same as /bookstore/book[1][@location='US']
unless the first element also happens to have that location attribute.
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