让我们考虑一个例子,a ='red table jet blue ghost hind'.现在我想要我作为b = ['red','table','jet','blue','ghost','hind'].在python中我们可以使用列表理解,但在Xquery中有没有像"List Comprehension"这样的方法?
XQuery基于XDM(XPath数据模型),其中有序列.
甲序列是像平面列表(这是不可能有序列的序列).
这是一个例子:
declare variable $a as xs:string := "red table jet blue ghost hind";
declare variable $b as xs:string* := tokenize($a, ' ');
Run Code Online (Sandbox Code Playgroud)
并且您可以验证这$b是一个完全符合所需字符串的序列:
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, '"')
Run Code Online (Sandbox Code Playgroud)
运行上面的XQUery代码时,会生成所需的正确结果:
"red" "table" "jet" "blue" "ghost" "hind"
Run Code Online (Sandbox Code Playgroud)