Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XQuery : how to try if a list contains a given string?

I have 2 XML files :

file1.xml

<data>doe90</data>
<data>foo</data>
<data>goo</data>
...

file2.xml

<data2>nan</data2>
<data2>goo</data2>
<data2>test</data2>
...

I stored this data in 2 vars :

let $data := //data,
$data2 := //data2

And began to do this :

for $d in $data2
return 
if() (: $d is also in $data ? :)

What should I do ? Thanks

EDIT : Of course I tried contains, but got an error :

if(contains($d,$data) = 0)

An exception occurred during query execution: XPTY0004: cannot convert 'xs:boolean(true)' to xs:integer

like image 858
Rob Avatar asked Dec 11 '22 19:12

Rob


1 Answers

This may help:

//data[. = //data2] ► returns elements whose string values are contained in data2 
//data = //data2    ► returns true there are any matches, false otherwise

fn:contains() won’t help here, as it was built for matching substrings:

contains('abc', 'a') ► true
like image 149
Christian Grün Avatar answered Dec 21 '22 10:12

Christian Grün