给定2个xml文件,每个文件中包含一个数字列表。
<list1>
<item>1</item>
<item>2</item>
...
</list1>
list1 = [1,2,3,4,5,7,8,9,10]
list2 = [1,4,6,2,8]
我只希望列表1中的数字大于列表2中的所有数字,我该怎么做?
我试过了,但是如果它大于list2中的数字之一而不是整个列表,它只会返回该数字。
for $x in doc("list1.xml")/item
for $y in doc("list2.xml")/item
where ($x > $y)
return $x
预先感谢,xquery中的新手。
使用XQuery 3.0,您可以使用fn:for-each
,在我看来,这使语法更好。因此,对于其中的每个项目,请$list1
检查是否存在$list2
较大的项目。
let $list1 := (1 to 10)
let $list2 := (1, 4, 6, 2, 8)
return for-each($list1, function($l) {
if (for-each($list2, function($x) {$l > $x}) = false())
then ()
else $l
})
如果您只有XQuery 1.0,它应该也可以正常工作,并且基本相同:
let $list1 := (1 to 10)
let $list2 := (1, 4, 6, 2, 8)
for $l in $list1
where not((
for $f in $list2
return $l > $f
) = false())
return $l
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句