XForms Functions

From http://www.w3schools.com (Copyright Refsnes Data)

# XForms Functions

XForms has some predefined functions. But you can also call functions defined in scripts.

## XForms Functions

The XForms function library includes the entire XPath 1.0 core function library.

The XPath core functions can be found here: http://www.w3schools.com/xpath/xpath_functions.asp

The following table lists the additional functions within XForms:

Function | Description
--- | ---
boolean-from-string(string) | Returns true if the parameter string is "true" or "1" and false if the parameter string is "false" or "0"
if(booleantest, string1, string2) | Evaluates the Booleantest parameter and returns string1 if the test is true, and string2 if the test is false

avg(node-set)

Returns the average of all the nodes in the specified node-set. The value of each node is converted to a number. If the node-set is empty it returns NaN

<values>
<value>10</value>
<value>50</value>
<value>0</value>
</values>

avg(/values/value)

Returns: 20

min(node-set)

Returns the minimum value of all the nodes in the specified node-set. The value of each node is converted to a number. If the node-set is empty it returns NaN

<values>
<value>10</value>
<value>20</value>
<value>0</value>
</values>

min(/values/value)

Returns: 0

max(node-set)

Returns the maximum value of all the nodes in the specified node-set. The value of each node is converted to a number. If the node-set is empty it returns NaN

<values>
<value>10</value>
<value>20</value>
<value>0</value>
</values>

max(/values/value)

Returns: 20

count-non-empty(node-set)

Returns the number of non-empty nodes in the specified node-set

<values>
<value>10</value>
<value>20</value>
<value>0</value>
<value />
</values>

count-non-empty(/values/value)

Returns: 3

index(string) | Returns the current index for a given repeat set

property(string)

Returns the property named by the string parameter

- property("version") - returns the XForms version number
- property("conformance-level") - returns the XForms conformance level ("basic" or "full")

now() | Returns the current system date and time in xs:dateTime format

instance(string)

An XForms Model can contain more than one instance. This function returns the root node of the specified instance data

<xforms:instance id="orderform">
<firstName>John</firstName>
</xforms:instance>

ref="instance('orderform')/firstName"

This example returns a node-set that consists of the firstName element node from the instance named "orderform"

days-from-date(string) | If the string parameter represents a legal xs:date or xs:dateTime, it returns the number of days between the specified date and 1970-01-01, otherwise it returns NaN days-from-date("2002-01-02") returns 11689 days-from-date("1969-12-29") returns -3
seconds-from-dateTime(string) | If the string parameter represents a legal xs:dateTime, it returns the number of seconds between the specified dateTime and 1970-01-01T00:00:00Z, otherwise it returns NaN

seconds(string)

If the string parameter represents a legal xs:duration, it returns the number specified in the seconds component plus 60 * the number specified in the minutes component, plus 60 * 60 * the number specified in the hours component, plus 60 * 60 * 24 * the number specified in the days component, otherwise it returns NaN

seconds("P1Y2M") returns 0
seconds("P3DT10H30M1.5S") returns 297001.5
seconds("3") returns NaN

months(string) | If the string parameter represents a legal xs:duration, it returns the number specified in the months component plus 12 * the number specified in the years component, otherwise it returns NaN months("P1Y2M") returns 14 months("-P19M") returns -19

From http://www.w3schools.com (Copyright Refsnes Data)