为什么我在XQuery中的范围搜索不起作用并且返回了太多的元素?

为什么我在XQuery中的范围搜索不起作用并且返回了太多的元素?,xquery,basex,Xquery,Basex,对XQuery和noob q来说都是新手。我安装了一个BaseXDB作为我的沙盒(包括一个示例文件etc/factbook.xml)。我构造了一个简单的查询,我认为它将返回所有人口>1000万的“城市” for $x in doc("etc/factbook.xml")/mondial/country where $x/city/population > 10000000.0 return $x/city 但我看到的是人口较少的城市,有什么见解吗 <city id="f0_17

对XQuery和noob q来说都是新手。我安装了一个BaseXDB作为我的沙盒(包括一个示例文件etc/factbook.xml)。我构造了一个简单的查询,我认为它将返回所有人口>1000万的“城市”

for $x in doc("etc/factbook.xml")/mondial/country
  where $x/city/population > 10000000.0
return $x/city
但我看到的是人口较少的城市,有什么见解吗

<city id="f0_1726" country="f0_553" longitude="126.967" latitude="37.5667">
  <name>Seoul</name>
  <population year="95">10229262</population>
</city>
<city id="f0_10300" country="f0_553">
  <name>Kunsan</name>
  <population year="95">266517</population>
</city>
 (I've only included first two but many more both < and > 10million)

首尔
10229262
昆山
266517
(我只包括了前两个,但更多的都是<1000万和>1000万)
您将返回所有城市人口超过1000万的国家。而是在城市上循环(请使用有意义的变量名):

或者使用XPath表达式执行相同的操作:

doc("etc/factbook.xml")/mondial/country/city[population > 10000000]
始终使用有意义的变量名。如果您将$city/city/population写为
where
,您可能会自己意识到这个错误。没有更多的字符,但更容易理解发生了什么。
doc("etc/factbook.xml")/mondial/country/city[population > 10000000]