XPath基于复杂过滤器计算子节点 [英] XPath to count the child nodes based on complex filter

查看:27
本文介绍了XPath基于复杂过滤器计算子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的 XML:

I have an XML in the following format:

<ComRequest>
  <root lineId="1" creator="jumnix">
    <component lineId="101">
        <compLine lineId="1001">1</compLine>
        <compLine lineId="1002">2</compLine>
        <compLine lineId="1003">3</compLine>
        <compLine lineId="1004">4</compLine>
        <compLine lineId="1005">5</compLine>
        <compLine lineId="1006">6</compLine>
        <compLine lineId="1007">7</compLine>
        <compLine lineId="1008">8</compLine>
        <compLine lineId="1009">9</compLine>
        <compLine lineId="1010">10</compLine>
        <compLine lineId="1011">11</compLine>
    </component>
    <component lineId="102">
        <compLine lineId="1012">12</compLine>
        <compLine lineId="1013">13</compLine>
        <compLine lineId="1014">14</compLine>
        <compLine lineId="1015">15</compLine>
        <compLine lineId="1016">16</compLine>
        <compLine lineId="1017">17</compLine>
        <compLine lineId="1018">18</compLine>
        <compLine lineId="1019">19</compLine>
        <compLine lineId="1020">20</compLine>
        <compLine lineId="1021">21</compLine>
        <compLine lineId="1022">22</compLine>
    </component>
  </root>
</ComRequest>

我需要获取具有 10 个以上compLine"元素的组件"节点的数量.直到现在我有以下 XPath 查询 -

I have a requirement to get the count of the 'component' nodes that have more than 10 'compLine' elements. Till now I have the following XPath query -

count(//*[local-name()='ComRequest']/*[local-name()='root']/*[local-name()='component']/*[local-name()='compLine' and count(self) gt 10])

但这不起作用(结果为0").感谢您对解决此问题的任何帮助.

But this does not work (gives a '0' result). Any help in getting this resolved is appreciated.

推荐答案

count(//ComRequest/root/component[count(compLine)>10]) 怎么样?

这篇关于XPath基于复杂过滤器计算子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆