fn:sum function

The fn:sum function returns the sum of the values in a sequence.

Syntax

>>-fn:sum(sequence-expression)---------------------------------><

sequence-expression
A sequence that contains items of any of the following atomic types, or an empty sequence:
  • xs:double
  • xs:decimal
  • xs:integer
  • A type that is derived from any of the previously listed types
  • Start of changexs:dayTimeDurationEnd of change
  • Start of changexs:yearMonthDurationEnd of change
  • xs:untypedAtomic

All values in the sequence must be of the same type or a derived type of the type, or must be promotable to a single common type. An xs:untypedAtomic value is promoted to the xs:double data type. A derived type is promoted to its direct parent data type.

Returned value

If sequence-expression is not the empty sequence, the returned value is the sum of the values in sequence-expression. The data type of the returned value is the same as the data type of the items in sequence-expression, or the data type to which the items in sequence-expression are promoted.

If sequence-expression is the empty sequence, fn:sum returns 0.0E0.

Example

The following function returns the sum of the sequence (5, 1.0E2, 4.5):

fn:sum(5, 1.0E2, 40.5)

The values are promoted to the xs:double data type. The returned value is 1.455E2.