【发布时间】:2018-07-27 09:36:19
【问题描述】:
我有如下代码,我想知道是否可以在不使用 FOR 循环的情况下获得相同的结果-
let $doc := cts:search(fn:doc(),
cts:element-value-query(......))
let $column-values := ("one,two,three....") (: Can be n number of values :)
let $tokenized-values := fn:tokenize($column-values, ",")
let $result := for $i in $doc
let $temp := for $j in $tokenized-values
return fn:concat("$i//*:",$j)
return <root>{xdmp:value($temp)}</root>
return <result>{$result}</result>
预期结果如下-
<result>
<root>
<one>abc</one>
<two>456</two>
<three>675</three>
</root>
<root>
<one>dfd</one>
<two>235</two>
<three>765</three>
</root>
</result>
我得到了结果,但是如果我想尽量减少 FOR 循环的使用,我怎样才能得到相同的结果。
有什么建议吗?
【问题讨论】:
-
你只有两个
for .. in表达式,为什么要消除它们? Marklogic 是否支持!运算符?这肯定是不使用for的一种方法,所以$tokenized-values!(concat("$i//*:",.)会重写你的第二个for $j。但你最好先解释一下为什么不想使用for表达式。 -
我的第一个“for”将遍历所有文档,无论我从搜索查询中获得什么,它都会降低我的性能。