Reputation: 2317
I am trying to pull some data from our XML-native db, IF the value of one element is in contained sequence of values. Don't think I worded that right. For example,
Given the following XML:
<root>
<a>1</a>
<root>
Seems there should be a way to do something like (excuse syntax, treat as pseudo)
where root/a in (1,2,3,4)
From all of my searching, that doesn't seem to be possible. At best, I've gotten:
where root/a = 1 or root/1 = 2 or root/a = 3 etc
is there a better way to do this?
Upvotes: 5
Views: 2617
Reputation: 89295
You can simply use =
operator :
where root/a = (1,2,3,4)
=
works on set values similar to contains, which is what you needed exactly. Contrast =
with eq
which requires atomic values for comparison.
Below is a complete example.
XML:
<root>
<parent>
<a>1</a>
</parent>
<parent>
<a>4</a>
</parent>
<parent>
<a>10</a>
</parent>
</root>
XQuery :
for $p in /root/parent
where $p/a = (1,2,3,4)
return $p
Output :
<parent>
<a>1</a>
</parent>
<parent>
<a>4</a>
</parent>
demo : xpathtester
Upvotes: 9