XQuery LIKE statement?

Is there a way to perform a LIKE operation with XQuery in the same way as with SQL?

I will not create some "startswith", "endswith" and "contains" -expressions.

An example of what I want to achieve:

for $x in /user where $x/firstname LIKE '%xxx' return $x
for $x in /user where $x/middlename LIKE 'xxx%' return $x 
for $x in /user where $x/lastname LIKE '%xxx%' return $x

Is there a way to achieve this in XQuery?

EDIT:

Got the answer to the question above. New issue:

Would there be a way to do it the other way around? I would like to run these queries using the sql statement equivalent to NOT LIKE. Is it possible? It must be in a FLWOR expression

EDIT2:

Solved a problem. You can run fn: not (start-with ('123', '1')) and returns false.

+5
source share
1 answer

XPath 2.0 XQuery 1.0 ( W3C) matches http://www.w3.org/TR/xpath-functions/#func-matches:

/user[matches(firstname, 'xxx$')]

, , , starts-with contains ( XPath 1.0/2.0), ends-with ( XPath 2.0), .

+13

All Articles