RationaleXForms 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.0You can use XPath 2.0 expressions everywhere XForms allows XPath expressions.Type annotationsBasicsSince 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" or:constraint=". le 150"/> <xforms:bind nodeset="date" type="xs:date" constraint=". le (current-date() + xdt:dayTimeDuration('P2D'))"/> Enabling type annotationsAs 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"/>
<xforms:model xxforms:expose-xpath-types="true"> Where does this work?Type annotations can be used in:
CaveatsComparisonsConsider:<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 valueAs 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:
<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 workOrbeon Forms needs to investigate the following questions:
|