datatype awareness in xpath duration calculation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

datatype awareness in xpath duration calculation

Adrian Baker-2
I created a bind to two dateTime fields, then a calculated bind which
calculates the difference as a xs:duration, eg:

<xforms:bind id="bind-intoTheatre" nodeset="intoTheatre"
type="xs:dateTime"/>
<xforms:bind id="bind-outOfTheatre" nodeset="outOfTheatre"
type="xs:dateTime"/>
<xforms:bind id="bind-operationLength" type="xs:duration"
calculate="instance('clinicalDocument')/body/CONCEPT99984) -
instance('clinicalDocument')/body/CONCEPT99985)"
nodeset="instance('visualFields')/operationLength"/>

However the operationLength bind results in NaN, because (I assume) both
nodes are treated as untyped by Saxon and get converted to doubles - and
since they aren't parsable as numbers you get NaN - NaN = NaN.

To make the calculation work I cast both nodes to xs:dateTime first,
which happily produces a duration:

<xforms:bind id="bind-operationLength" type="xs:duration"
calculate="xs:dateTime(instance('clinicalDocument')/body/CONCEPT99984) -
xs:dateTime(instance('clinicalDocument')/body/CONCEPT99985)"
nodeset="instance('visualFields')/operationLength"/>

The question is, given that the engine 'knows' that each of the input
nodes is an xs:dateTime, should the cast really be necessary? What
org.orbeon.saxon.dom4j.NodeWrapper was modified so that
getTypeAnnotation() returned the type specifed on the bind, if any? Or
would this rely upon the schema aware version of Saxon?

A final question: the duration produced is displayed in it's ugly native
format ("PT3H57M"). Is it the form author's job to format this nicely
(which I believe can be achieved using a spaghetti of xpath)? Or would
this be a feature desirable in the engine itself - similar to the way
dates are presented in xforms:output elements? (and eventually input
support also)?

Adrian









--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: datatype awareness in xpath duration calculation

Alessandro  Vernet
Administrator
On 2/13/06, Adrian Baker <[hidden email]> wrote:
> The question is, given that the engine 'knows' that each of the input
> nodes is an xs:dateTime, should the cast really be necessary? What
> org.orbeon.saxon.dom4j.NodeWrapper was modified so that
> getTypeAnnotation() returned the type specifed on the bind, if any? Or
> would this rely upon the schema aware version of Saxon?

Adrian,

The XForms server is using Saxon to evaluate XPath expressions (not
dom4j). Could Saxon be "told" what the type of some nodes are, based
on your <xforms:bind type="...">, and then could this information be
used so you wouldn't have to do casts in XPath expressions? Maybe this
is possible, at least with simple types. Your suggesting makes sense,
so if you find how to do this, we will be happy to integrate your code
in PresentationServer.

> A final question: the duration produced is displayed in it's ugly native
> format ("PT3H57M"). Is it the form author's job to format this nicely
> (which I believe can be achieved using a spaghetti of xpath)? Or would
> this be a feature desirable in the engine itself - similar to the way
> dates are presented in xforms:output elements? (and eventually input
> support also)?

If you just want to format a duration for display, you can the
xxforms:format attribute (see "5.3. xforms:output" at the URL below).
For the input, some kind a generic input filter/output filter
solution, as discussed in another thread, would solve the problem.

http://www.orbeon.com/ops/doc/reference-xforms-ng

Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet