[英]XPath expression to get count of the child elements
我有這樣的XML
<Root>
<Mgr name="X">
<Emp name = "X1"/>
<Emp name = "X2"/>
<Emp name = "X3"/>
</Mgr>
<Mgr name="Y">
<Emp name = "Y1"/>
<Emp name = "Y2"/>
</Mgr>
</Root>
我可以輕松地使用此count(/Root/Mgr/Emp)
獲得總員工,但我希望得到每個經理的計數。
像這樣的東西 - '3,2'。
這個XPath 1.0表達式,
concat(count(/Root/Mgr[1]/Emp), ',', count(/Root/Mgr[2]/Emp))
將返回
3,2
根據要求提供XML。
這個XPath 2.0表達式,
string-join(/root/Mgr/count(Emp), ',')
將返回
3,2
根據要求提供XML(並且很好地概括了兩個Mgr
元素)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.