The avg() Function

Release 2.0 - ...

Syntax

  CopyCode image Copy Code
number avg(node-set)

Description

Function avg() returns the arithmetic average of the result of converting the string-values of each node in the argument node-set to a number. The sum is computed with sum(), and divided with div by the value computed with count(). If the parameter is an empty node-set, or if any of the nodes evaluate to NaN, the return value is NaN.

Example

XML CopyCode image Copy Code
<xforms:model>
   <xforms:instance xmlns:ex="http://example.org">>
      <ex:root>
         <ex:value>2</ex:value>
         <ex:value>6</ex:value>
      </ex:root>
   </xforms:instance>
</xforms:model>
 ...
<xforms:group>
   <xforms:output value="avg(ex:value)">
      <xforms:label>Average : </xforms:label>
   </xforms:output>
</xforms:group>

The above example will return 4.

Specification

Link to the XForms specification: the avg() function.