Get book nodes where node and parent node contains an attribute

Miguel Oz
Miguel Oz used Ask the Experts™
on
Please provide xpath expresion for the problem below:
 
From the sample xml shown in the link below.
http://stackoverflow.com/questions/1457638/xpath-get-nodes-where-child-node-contains-an-attribute

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
Comment
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
Commented:
Try this:
//book/title[@lang='en' and ../@category='WEB']

Open in new window

You could also try:

//book[@category='WEB']/title[@lang='en']

For more information on XPATH, take a look at

http://www.w3schools.com/xpath/xpath_syntax.asp
Miguel OzSenior Software Engineer
Top Expert 2009

Author

Commented:
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