基于深层属性的过滤

Filtering based on an attribute in deep level

运行 BaseX 上的 Xquery。

我想根据深层属性 (/BLA1/BLA2/BLA3) 进行过滤,但是 return 属性同时来自过滤级别和高于它的级别 (/BLA1/BLA2)。

因此,据我了解,我的“for”必须在上层 (运行) (/BLA1/BLA2) 才能允许。但是我无法使过滤工作.. 当我尝试 运行 在更深层次上使用“for”时 - 它确实有效但是我无法 return 我需要的属性上层。

这个有效:我根据过滤得到了所需的结果。

for $i in /BLA1/BLA2/BLA3
where $i/@AT1>1000 and $i/@AT2='XX'
return $i/data(@AT3)

这个不起作用,意思是过滤器没有过滤,我得到的结果是 $i/BLA3/@AT2 不是 XX。

for $i in /BLA1/BLA2
where $i/BLA3/@AT1>1000 and $i/BLA3/@AT2='XX'
return $i/BLA3/data(@AT3)

我不明白为什么第二个不起作用...

这是我真正想要使用的,即return一个来自上层(/BLA1/BLA2)的属性和另一个来自过滤层的属性(/BLA1/BLA2/BLA3)

for $i in /BLA1/BLA2
where $i/BLA3/@AT1>1000 and $i/BLA3/@AT2='XX'
return $i/data(@AT4) || ' ' || $i/BLA3/data(@AT3)

任何帮助将不胜感激!

使用..向上导航,例如

for $i in /BLA1/BLA2/BLA3
where $i/@AT1>1000 and $i/@AT2='XX'
return $i/../data(@AT4) || ' ' || $i/data(@AT3)