如何在 xQuery 中组合Where 子句

use*_*443 2 xquery

我不确定我在这里做错了什么,但我试图通过使用“where”设置两个条件,它们各自单独工作,但是当我将它们组合起来时,我会得到每个文件的转储。

如果我只是有:

for $i in collection("/db/people")
where $i//lastname="Smith"
return $i
Run Code Online (Sandbox Code Playgroud)

我得到两个列表,因为有两种类型(a 和 b)。

如果我有

for $i in collection("/db/people")
where $i//type="a"
return $i
Run Code Online (Sandbox Code Playgroud)

我收到了 538 个列表,其中所有内容都是“a”类型。

但是,如果我有:

for $i in collection("/db/people")
where  $i//type="a" and $i//lastname="Smith"
return $i
Run Code Online (Sandbox Code Playgroud)

我得到了所有的文件。为什么它不只给我一个具有我指定的名称和类型的文件?看来我错过了一些明显的东西!

wca*_*lon 5

您可以在http://try.zorba-xquery.com/上尝试您的解决方案,它工作正常。例如:

let $people := (<people><type>a</type><lastname>Smith</lastname></people>, <people><type>a</type><lastname>Foobar</lastname></people>)
for $i in $people
where  $i//type="a" and $i//lastname="Smith"
return $i
Run Code Online (Sandbox Code Playgroud)