'OR' operator in XPath predicate?

abernier picture abernier · Feb 6, 2010 · Viewed 30.8k times · Source

What is the XPath expression to select <link> elements with type="application/rss+xml" OR type="application/atom+xml" (RSS and Atom feeds)

  • link[@rel='alternate'][@type='application/rss+xml'] selects RSS feeds
  • link[@rel='alternate'][@type='application/atom+xml'] selects Atom feeds

But what is the single XPath expression for selecting them both?

Thank you.

Answer

Jonathan Fingland picture Jonathan Fingland · Feb 6, 2010

use:

link[@rel='alternate'][@type='application/rss+xml' or @type='application/atom+xml'] 

see http://www.w3.org/TR/xpath/#NT-OrExpr

You could also use union to accomplish this

link[@rel='alternate'][@type='application/rss+xml']|link[@rel='alternate'][@type='application/atom+xml']

but or will do.