This section defines the various number functions provided by the XForms core function library. These functions were added to the XForms core because they were missing in the XPath core but deemed necessary for typical form-based applications. Some of these functions are being adopted by the XPath working group for inclusion in XPath 2.0.
6.3.1 Computing Minimum, Maximum, and Average
The XPath core function library defines a number of functions like sum that reduce a node-set by applying a given mathematical operation. XForms extends these with the following functions:
In Figure 6.2, we illustrate the use of these functions with a fragment from a census report.
Figure 6.2 Functions min , max , and avg used in a census report.
< html xmlns ="http://www.w3.org/1999/xhtml" xmlns:xf ="http://www.w3.org/2002/xforms"> < head >< title >Census Report</ title > < xf:model id ="data"> < xf:instance xmlns =""> < census > < state >< population /></ state > </ census ></ xf:instance > </ xf:model ></ head > < body > < xf:group xmlns ="http://www.w3.org/2002/xforms"> < output value ="min(/census/state/population)"> < label >Smallest population</ label ></ output > < output value ="max(/census/state/population)"> < label >Largest population</ label ></ output > < output value ="avg(/census/state/population)"> < label >Avg state population</ label ></ output > </ xf:group ></ body > </ html >
6.3.2 Function index for Addressing repeat Structures
Function index takes a string argument that is the id of a repeat structure. It returns the current value of the repeat index for that repeat structure. We used function index in creating add, remove, and scroll controls in Figure 4.13 and Figure 4.23.
6.3.3 Function count-non-empty
The XPath core contains function count that returns the number of nodes in a node-set. XForms adds a count-non-empty function, which first reduces the input node-set by removing all empty nodes before applying function count . Here, a node is said to be empty if and only if the string representation of the contents of that node has length 0.