Xpath Is there a less verbose way to filter with multiple 'contain' conditions?

40 Views Asked by At
and (contains(BusinessType,'Restaurant') or contains(BusinessType,'Pub') or contains(BusinessType,'Takeaway') <snip...>)

The above works as expected returning cases containing the specified words, but is there a less verbose/more efficient code?

Something like this, but actually works?

and (contains(BusinessType,'Restaurant|Pub|Takeaway'))
2

There are 2 best solutions below

0
Mads Hansen On BEST ANSWER

matches() takes a regex and will do what you want:

matches(BusinessType,'Restaurant|Pub|Takeaway')
0
kjhughes On

If you truly want substring containment testing against a set of possible substrings (i.e. BusinessType should match not only 'Restaurant' but also 'Fine Dining Restaurant' and 'Non-Restaurants'), then see Mads' answer (+1).

If you actually want string equality testing against a set of possible values, update the regex as follows,

matches(BusinessType, '^(Restaurant|Pub|Takeaway)$')

or use this cleaner form instead:

BusinessType = ('Restaurant', 'Pub', 'Takeaway')