I was trying to query for a XML file
<?xml version="1.0" encoding="UTF-8"?>
<family>
<person salary="1000">
<name>Maria Fischer</name>
<person salary="750">
<name>Helmut Fischer</name>
<person salary="830">
<name>Maria Helbing</name>
<person salary="0">
<name>David Helbing</name>
</person>
</person>
</person>
</person>
</family>
This is a hierarchy of persons in which a parent/child relationship in the XML document represents a parent/child relationship in the family. I want to query for the total sum of the salary of the whole family using XQUERY. I know somehow I have to use nested FLWOR return and fn:sum. I've tried
for $p in doc("family.xml")/family
return
for $p in $p/person
return $p
I believe this can extract all the node in XML. But I still don't know how to extract the salary attributes and sum them up. I'm pretty new to XQUERY and haven't seen related questions on stackflow. XQuery Nested For Loop seems related but I still cannot figure it out. Please help!