Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XPath:收集同时聚合问题_Xml_Xpath_Xpath 2.0 - Fatal编程技术网

Xml XPath:收集同时聚合问题

Xml XPath:收集同时聚合问题,xml,xpath,xpath-2.0,Xml,Xpath,Xpath 2.0,我有一个结构如下的XML文件: <person height="170"/> <person height="155"/> <person height="192"/> ... <tree height="100"/> <tree height="300"/> <tree height="120"/> ... 我需要返回所有至少有3棵树且高度在此人身高+-10范围内的人员 例如,如果一个人的身高为155,则当至少有3棵

我有一个结构如下的XML文件:

<person height="170"/>
<person height="155"/>
<person height="192"/>
...
<tree height="100"/>
<tree height="300"/>
<tree height="120"/>

...
我需要返回所有至少有3棵树且高度在此人身高+-10范围内的人员

例如,如果一个人的身高为155,则当至少有3棵树的高度在145到165之间时,该人将被返回

我尝试实施它,并取得了以下成果:

//person[count(//tree[@height >>>>>>is in range 10 to person's height<<<<<]) >= 3]

//person[count(//tree[@height>>>>>>>在10到人的高度范围内这是一个可以使用
的$me in的地方。
习惯用法:

//person[count(for $me in . return //tree[
    @height <= ($me/@height + 10) and @height >= ($me/@height - 10)]) >= 3]
//person[count(对于$me in.return//tree[
@高度=($me/@height-10)])>=3]

在这里,我使用一次迭代
for
表达式来捕获当前的
person
(第一级谓词的
),以便在第二级谓词中引用它(其中
).

我本以为会有一些语法糖来取代这个可怕的习惯用法,但它很管用,所以我不能抱怨:)@Mugen我总是觉得有点奇怪,
for
是XPath的一部分,而
let
只是XQuery。