XQuery:为什么我的请求在许多XML文件中都不起作用?

时间:2012-12-23 11:17:53

标签: xml xquery

我有2个XML文件,第一个包含气象测量,第二个包含位置数据:

measures.xml

<measure latitude="45.90298482482" longitude="8.92092094">
   ...
</measure>
<measure latitude="45.29848284" longitude="8.72474724">
   ...
</measure>
...

locations.xml

<location latlng="45.9029,8.9209">
    <address>8, Denver Road</address>
    <place>Goodcity</place>
</location>
<location latlng="45.2984,8.7247">
    <address>3, New Avenue</address>
    <place>Goodcity</place>
</location>

所以我想要做的是:存储给定位置的所有latlng,然后尝试通过使用子串获取与之对应的度量。这是我尝试过的,但一直返回0:

for $l in //location
where $l/place/string() = 'Goodcity'
return
let $test := $l/@latlng/string() 
return
for $m in //measure
where concat(substring($m/@latitude/string(),0,8),',',substring($m/@longitude/string(),0,7)) = $test
return $m

有什么想法吗?

编辑:问题不是来自我使用susbtring(lat,0,8)substring(long,0,7)的事实,我知道我的位置文件,这些将始终返回4位小数。

编辑2:最后它有效,虽然我的请求很长,你认为有办法简化吗?

1 个答案:

答案 0 :(得分:1)

如果有两个单独的XML文档,那么我希望看到类似

的内容
for $l in doc('location.xml')//location...

for $m in doc('measures.xml')//measure...

使用substring()进行比较似乎非常容易出错。为什么45.90298482482四舍五入为45.9029而不是45.9030?但我想你比我们更了解你自己的数据。