XPath OR operator for different nodes

user569008 picture user569008 · Mar 18, 2011 · Viewed 172.6k times · Source

How can I do with XPath:

//bookstore/book/title or //bookstore/city/zipcode/title

Just //title won't work because I also have //bookstore/magazine/title

p.s. I saw a lot of or examples but mainly with attributes or single node structure.

Answer

Stephan picture Stephan · Mar 18, 2011

All title nodes with zipcode or book node as parent:

Version 1:

//title[parent::zipcode|parent::book]

Version 2:

//bookstore/book/title|//bookstore/city/zipcode/title