Comments? Feedback?

This wiki does not yet support public comments (a limitation of Google Sites), so we encourage you to post your comments on Twitter by responding to @orbeon.

Recent site activity

XPath 2.0 Support

Rationale

XForms 1.1 only specifies support for XPath 1.0 in XForms. On the other hand Orbeon Forms supports XPath 2.0 since the beginning.

Using XPath 2.0

You can use XPath 2.0 expressions everywhere XForms allows XPath expressions.

Type annotations

Basics

Since July 2009, Orbeon Forms supports exposing MIP type annotations to XPath 2.0.

This means that if you have a type associated with a node, e.g.:

<xforms:bind nodeset="age" type="xs:positiveInteger"/>

then the type is not only used for validation, but also determines the typed value of the element node age.

This means that earlier, you had to write the following:

<xforms:bind nodeset="age" type="xs:positiveInteger"
  constraint="xs:integer(.) le 150"/>

With exposing type annotations, you can simply write:

<xforms:bind nodeset="age" type="xs:positiveInteger"
  constraint=". le 150"/>


or:

<xforms:bind nodeset="date" type="xs:date"
  constraint=". le (current-date() + xdt:dayTimeDuration('P2D'))"/>

Enabling type annotations

As of July 2009, type annotations are not automatically enabled for backward compatibility reasons.

The following property controls whether instance types annotations are exposed to XPath 2.0 expressions:

 <property as="xs:boolean" name="oxf.xforms.expose-xpath-types" value="true"/>
  • If set to false (the default), instance types are not made available to XPath expressions.
  • If set to true, they are made available.
You can as usual enable this on a per-page basis:

<xforms:model xxforms:expose-xpath-types="true">

Where does this work?

Type annotations can be used in:
  • xforms:bind/@validation
  • actions
  • control bindings and attributes
Type annotations currently don't work in:
  • xforms:bind/@calculate
The reason for that is that calculations occur during the recalculation phase of the model, and type annotations are computed during the revalidation phase of the model, which usually takes place later. So the types are not available during revalidation.

Caveats

Comparisons

Consider:

<xforms:bind nodeset="is-soap" type="xs:boolean"/>
...
<xforms:action if="is-soap = 'true'">

This will cause an XPath dynamic error, because is-soap is a boolean, true is a string, and there is no automatic conversion between the two. Instead, write:

<xforms:action if="is-soap = true()">

XForms requested type vs. XPath typed value

As per XPath 2.0 semantic, when XPath expressions access typed nodes, they expect them to have valid values for the given type.

In order to match this semantic:
  • The XForms engine passes an XForms type to the XPath engine for a node only if that node contains a value actually matching that type.
  • Otherwise, the XForms engine tells the XPath engine that the value is untyped.
Consider:

<xforms:bind nodeset="name" type="xs:NCName"/>
...
<xforms:output value="concat(name, '-suffix')"/>

In this example, if the node called name has e.g. an empty value, it will be marked as invalid. But in addition, the XPath expression in xforms:output would cause an XPath dynamic error if the type of the node as seen by XPath was xs:NCName, because the value is not of type NCName when empty. In this case, therefore, the XForms engine does not pass to XPath the xs:NCName type, but mark it instead as untyped. In other words, depending on the data on which it runs, an XPath expression might see the typed you specified for the node, or it might see an untyped value.

The above means you must be just a bit more cautious about which types you use with type annotations!

Notes on future annotations work

Orbeon Forms needs to investigate the following questions:
  • Handling of dynamic XPath errors
    • in @calculate, @constraint, @value, etc.
    • must log warning and/or dispatch XForms error, but not stop processing
  • When do type annotations occur.
    • Currently, they occur during XForms revalidation
    • As mentioned above, this makes them unavailable for @recalculate
    • XFormsModelBinds could be modified to perform type annotations before recalculation
  • Whether the XML Schema validator (we use MSV) is able to annotate elements and attribute which are not valid. Currently, it does not.