XPath to select element based on childs child value

The Solution to XPath to select element based on childs child value is


Almost there. In your predicate, you want a relative path, so change

./book[/author/name = 'John'] 

to either

./book[author/name = 'John'] 

or

./book[./author/name = 'John'] 

and you will match your element. Your current predicate goes back to the root of the document to look for an author.

~ Answered on 2012-03-13 11:31:34


Most Viewed Questions: