Core XForms functions

The XForms Core Function Library includes the entire XPath Core Function Library, including operations on node-sets, strings, numbers, and booleans. In addition XForms adds the functions described in the following sections.

days-from-date()

number days-from-date(string)

This function returns a whole number of days, according to the following rules:

  1. If the string parameter represents a legal lexical xsd:date or xsd:dateTime, the return value is equal to the number of days difference between the specified date or dateTime (normalized to UTC) and 1970-01-01.
  2. Hour, minute, and second components are ignored after normalisation.
  3. Any other input parameter causes a return value of NaN.

Examples:

days-from-date("2002-01-01")

returns 11688

days-from-date("1969-12-31")

returns -1

More examples

days-to-date()

string days-to-date(number)

This function returns a string containing a lexical xsd:date that corresponds to the number of days passed as the parameter according to the following rules:

  1. The number parameter is rounded to the nearest whole number.
  2. The result is interpreted as the difference between the desired date and 1970-01-01.
  3. An input parameter value of NaN results in output of the empty string.

Examples:

days-to-date(11688)

returns 2002-01-01

days-to-date(-1)

returns 1969-12-31

More examples

instance()

node-set instance(string)

An XForms Model can contain more that one instance. This function allows access to instance data, within the same XForms Model, but outside the instance data containing the context node.

The argument is converted to a string as if by a call to the string function. This string is treated as an IDREF, which is matched against instance elements in the containing document. If a match is located, and the matching instance data is associated with the same XForms Model as the current context node, this function returns a node-set containing just the root element node (also called the document element node) of the referenced instance data. In all other cases, an empty node-set is returned.

Example:

For instance data corresponding to this XML:

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

The following expression selects the firstName node. Note that the instance function returns an element node, effectively replacing the leftmost location step from the path:

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

power()

number power(number, number)

Raises the first argument to the power of the second argument, returning the result. If the calculation does not result in a real number, then NaN is returned.

Examples:

power(-1, 0.5)

returns NaN.

if (prin>0 and dur>0 and rate>0, prin*rate/(1-power(1+rate, -dur)), 0)

returns a compounded interest payment value given a non-zero principal (prin), duration (dur) and periodic interest rate (rate).

More examples.