Is it possible to specify an XPath query such that it can count the number at the text-value of a set of children:
This is best explained with an example, for instance:
<badge_counts>
<gold>2</gold>
<silver>15</silver>
<bronze>32</bronze>
</badge_counts>
Thus, is it possible to specify an Xpath, to get total_badges = 49. (from: 2+15+32)
Use:
This produces the sum, of the string-values converted to number, of all elements in the XML document that are children of the top element of the document.
As a rule: Whenever possible try to avoid using the
//pseudo-operator, because this may lead to unwanted inefficient evaluation — many XPath engines in this case perform complete traversal of the whole tree rooted in the context node.XSLT – based verification:
This transformation:
when applied on the provided XML document:
evaluates the XPath expression and outputs the result: