XPath来计算基于复杂筛选器的子节点



我有一个以下格式的XML:

<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"元素的"component"节点的计数。到目前为止,我有以下XPath查询-

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

但这不起作用(结果为"0")。如有任何帮助,我们将不胜感激。

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

@Bala-R(+1)使用兼容的XSLT1.0处理器(Saxon)进行了正确评估:

count(//ComRequest/root/component[count(compLine)>10])

或者,

count(/*/*/*[count(compLine)>10])

否则,您的测试、上下文(与问题中提供的上下文不同)或xpath计算器中会出现问题。

最新更新