Reputation: 327
Lets consider an example, a = 'red table jet blue ghost hind'. Now i want i as b = ['red', 'table', 'jet', 'blue', 'ghost', 'hind']. In python we can use list comprehension, but in Xquery is there any method like "List Comprehension" ?
Upvotes: 1
Views: 5088
Reputation: 243529
XQuery is based on the XDM (XPath Data Model) in which there are sequences.
A sequence is something like a flat list (it isn't possible to have a sequence of sequences).
Here is an example:
declare variable $a as xs:string := "red table jet blue ghost hind";
declare variable $b as xs:string* := tokenize($a, ' ');
And you can verify that $b
is a sequence exactly of the wanted strings:
declare variable $a as xs:string := "red table jet blue ghost hind";
declare variable $b as xs:string* := tokenize($a, ' ');
for $s in $b
return
concat('"', $s, '"')
When the above XQUery code is run, the wanted, correct result is produced:
"red" "table" "jet" "blue" "ghost" "hind"
Upvotes: 7