Given a sequence, returns the average value of the items in the sequence.
A sequence of values.
The average of the given sequence. You can calculate
averages for six different datatypes:
Given a sequence of numeric values, the XSLT processor returns the average of those numbers, converting datatypes as necessary. Given a sequence of durations, the XSLT processor returns the average of those durations.
assumes you’ll send it a sequence containing sensible data; if
not, the XSLT processor throws an error. Asking for the average of
(42, 57, 'blue')
returns an error, as you’d expect.
Some notes about how the
avg() function works:
To calculate the average of a sequence of durations, all
the values must be
xs:yearMonthDurations. You can’t mix
the two types of durations; if you do, the XSLT processor
throws an error.
If all the items in the sequence are of type
xs:untypedAtomic, the XSLT processor
attempts to cast each value to
any item in the sequence can’t be
converted to an
the XSLT processor throws an error.
Finally, if you pass the
avg() function the empty
sequence, the function returns the empty sequence. Although
you’re not giving the function any useful data in this case,
the XSLT processor doesn’t throw an error.
XQuery 1.0 and XPath 2.0 ...