XPath 2.0 type annotations

From W3C XForms Group Wiki (Public)
Jump to: navigation, search

ErikBruchez to start

An XForms implementation based on XPath 2.0 could also make great use of type annotations. Right now, if you write:

  <xf:bind nodeset="foo" type="xs:decimal"/>
  <xf:bind nodeset="bar" calculate="../foo div 2"/>

then the xs:decimal type is not used at all by the @calculate expression.

XPath 2.0 OTOH has a notion of "typed value", which is used in "Arithmetic expressions, Comparison expressions, Function calls and returns, Cast expressions". [1] So in the same way that a Schema-aware XSLT 2.0 implementation can use the type information, an XForms implementation could use it too. In the example above, ../foo will first be atomized to an xs:decimal value, as if you had written xs:decimal(../foo). This can be very powerful and avoid a lot of casting of numeric values and dates in particular.