Get book nodes where node and parent node contains an attribute

Miguel Oz
Miguel Oz used Ask the Experts™
Please provide xpath expresion for the problem below:
From the sample xml shown in the link below.

The required xpath expression is : all book titles whose language="en" (English attribute in node)  and category="WEB" (parent)

Solution should look like:
 //book/title[@lang='en' and <your expression goes here>]

The expected result is:
  <title lang="en">XQuery Kick Start</title>
  <title lang="en">Learning XML</title>

Thank you
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Try this:
//book/title[@lang='en' and ../@category='WEB']

Open in new window

You could also try:


For more information on XPATH, take a look at
Miguel OzSenior Software Engineer
Top Expert 2009


Thanks, both answers are correct.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial