1
votes

Is there a way to select the sum of all nodes within 1 XML nocument

for $c in doc("http://www.dbis.informatik.uni-goettingen.de/Mondial/mondial.xml")
return count($c//country)

That is what i currently have but this only returns the count of all top level nodes. I would like to count all existing nodes.(recursively?)

1
So you want to count all country elements in the XML? How about count(doc("....")//country)? - har07
Perhaps you need to explain the requirement with an example input and output. I find it hard to believe that your requirement is simply to "count all nodes" since that's simply count(//node()) - unless you want namespaces and attributes as well. - Michael Kay
No that was pretty much what i was looking for. - joachim

1 Answers

4
votes

To count all nodes in this XML document, the following XPath expression suffices:

count(doc("http://www.dbis.informatik.uni-goettingen.de/Mondial/mondial.xml")//node())