[英]XPath to count the child nodes based on complex filter
我有一個 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”元素的“組件”節點的計數。 到目前為止,我有以下 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) 使用兼容的 XSLT 1.0 處理器 (Saxon) 正確評估:
count(//ComRequest/root/component[count(compLine)>10])
或者,要么
count(/*/*/*[count(compLine)>10])
否則,您的測試、您的上下文(與問題中提供的上下文不同)或您的 xpath 評估程序會出現問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.