Xquery如何使用多个元素中的过滤来获取包含所有节点的xml文件?

时间:2016-04-26 15:09:37

标签: xquery basex

如果我使用以下请求

collection('vagelisdb')[SensorInfo/Position/x>4]

我可以收到满足我对x> 4

的期望的xml的所有节点

但它不起作用我想在一个更深的节点中过滤

collection('vagelisdb')[SensorInfo/Position/x>4/anothernodename/y<2]

我想只收到满足x&gt; 4和y&lt; 2期望的节点,但我想要整个xml。这也意味着从SensorInfo

开始的节点

为了提供更多细节,xml就像这样

<SensorInfo>
    <Position>
        <x>2</x>
        <anothernodename>
            <y>3</y>
        </anothernodename>
    </Position>
    <Position>
        <x>5</x>
        <anothernodename>
            <y>1</y>
        </anothernodename>
    </Position>
</SensorInfo>

我想收到

<SensorInfo>
    <Position>
        <x>5</x>
        <anothernodename>
            <y>1</y>
        </anothernodename>
    </Position>
</SensorInfo>

2 个答案:

答案 0 :(得分:1)

只需使用and

collection('vagelisdb')[SensorInfo/Position/x>4 and SensorInfo/Position/anothernodename/y<2]

答案 1 :(得分:0)

选择所需的Position个节点: collection('vagelisdb')/SensorInfo/Position[x>4 and anothernodename/y<2]

将这些结果包装在您可以使用的SensorInfo元素中 element SensorInfo { collection('vagelisdb')/SensorInfo/Position[ x>4 and anothernodename/y<2] }