This section defines the various date-time functions provided by the XForms core function library. The mismatch between the data types available in XML Schema and XPath is most noticeable when working with values of type xsd:date and xsd:duration or any of their derived data types. This discrepancy is being addressed in XPath 2.0. XForms 1.0 provides an interim solution by defining date-time functions in the XForms core to meet the most common use cases encountered when creating electronic forms. The date-time functions in the XForms core accept string representation of the appropriate schema types and return a numeric XPath result. They have been designed for use within XPath expressions that appear within property calculate or constraint . Note that all of these functions take legal string representations of the underlying XML Schema type such as xsd:date or xsd:dateTime .
We used function days-from-date in model property constraint in Figure 5.8. Date and time functions are most useful when creating XForms applications that manipulate XML documents dealing with time values, for example, travel bookings or task lists. 6.5.1 Function nowOnline transactions may need to capture the time at which a transaction was completed. This can be done by including the current time in the submitted instance. The XForms core library defines a now function that returns the string representation of the current time as represented by type xsd:dateTime . The value returned by this function can be used in a variety of use cases, for example, to time-stamp data that is being submitted (see Figure 6.4). This is achieved by creating an action handler [2] within element model that stores the value returned by now in the instance to be submitted.
|