Given the following XML document :
<?xml version="1.0" encoding="UTF-8"?>
<values>
<value>1</value>
<value>3</value>
<value>5</value>
</values>
We can produce an XML document describing the sum of the values with the following XQuery :
<total>{sum(/values/value)}</total>
Which will result in the following document :
<?xml version="1.0" encoding="UTF-8"?>
<total>9</total>