Nokogiri xpath() 'or' operator?
Asked Answered
M

3

6

Is there a way I can accomplish the following using Nokogiri's xpath() ?

doc.xpath("//pod[@id=or('anid','anotherid')]")
Mallorymallow answered 14/12, 2011 at 20:22 Comment(0)
H
9

Try doc.xpath("//pod[@id='anid' or @id='anotherid']")

Helbonna answered 14/12, 2011 at 20:27 Comment(2)
perfect, that worked! That isn't XPath 2.0 syntax though, right?Mallorymallow
@MarkF No it isn't, it's XPath 1.0. In XPath or works as an operand (like something or something), not as a function (like or(something, something)).Helbonna
P
3

Try this XPath:

doc.xpath("//pod[@id='anid' or @id='anotherid']")
Pulsimeter answered 14/12, 2011 at 20:28 Comment(0)
T
1

This also worked for me:

sect_pr.xpath("//pod[@id='anid']", "//pod[@id='anotherid']")

It returns NodeSet

I got code like this:

sect_pr.xpath('//w:headerReference or //w:footerReference')

And it return true insted NodeSet

Thenceforth answered 30/5, 2016 at 12:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.