Comments? Feedback?

This wiki does not yet support public comments (a limitation of Google Sites), so we encourage you to post your comments either:

On Twitter by responding to @orbeon.

On our community mailing list: subscribe sending an email to ops-users-subscribe@ow2.org (content of subject/body doesn't matter), you'll get a response with the email to use to send your message to the community mailing list.

Recent site activity

XForms - XPath 2.0 Support

This allows much greater flexibility in the expressions you can use in Orbeon Forms (and once you have tasted XPath 2.0, you won't want to go back to XPath 1.0!).

Compatibility notes

In general, using XPath 2.0 does not cause incompatibilities: most XPath 1.0 expressions work without issues with an XPath 2.0 implementation.

XForms if() function

The use of the XForms 1.0/1.1 if() function clashes with XPath 2.0's built-in if (...) then ... else ... construct.

The bottom line is that you cannot directly use the XForms if() function in Orbeon Forms. The following, for example, will not work in Orbeon Forms:

if (normalize-space(/first-name) = '', '', concat('Hello, ', /first-name, '!'))

The good news is that you have ways around this issue:

Use the XPath 2.0 if (...) then ... else ... construct instead:

if (normalize-space(/first-name) = '') then '' else concat('Hello, ', /first-name, '!')

Use the Orbeon Forms xforms:if() extension, which behaves like the XForms if() function:

xforms:if (normalize-space(/first-name) = '', '', concat('Hello, ', /first-name, '!'))

XForms seconds-from-dateTime() function

The XForms 1.0/1.1 seconds-from-dateTime() function clashes with the XPath 2.0 function of the same name:
  • they take a parameter of different types
  • they do not have the same semantic
[SINCE: 2011-02-24]
  • The XForms version of the function is available as xforms:seconds-from-dateTime().
  • The XPath 2.0 version of the function is available without a namespace as seconds-from-dateTime().

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.

Sign in  |  Recent Site Activity  |  Revision History  |  Terms  |  Report Abuse  |  Print page  |  Powered by Google Sites