RE: [xsl] date calculations

Subject: RE: [xsl] date calculations
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 26 Mar 2007 09:50:14 +0100
> > StartTime + Duration
> This feels a bit wrong to me, along the lines of augmenting 
> the xml with defaulted attributes - by doing this aren't you 
> then relying on the input being validating every time the 
> transform runs, even if the xml hasn't changed?

Yes, you're relying on the input being typed, and it would certainly be my
recommendation to make that assumption explicit in your code, for example by

<xsl:template match="document-node(schema-element(invoice))">
   ... process an invoice ...

<xsl:template match="/">
  <xsl:message terminate="yes">Input document is not a validated

That's a better way of doing it than writing a cast, I think.

> You don't seem to be gaining much over being explicit with 
> the types in the stylesheet...

In this example, that's possibly true. When you're calling a lot of
functions, I think the benefits become clearer.

I have to admit I wasn't a great enthusiast for doing date-time-duration
arithmetic by overloading the arithmetic operators rather than by using
custom functions. Two reasons: (a) it means I can't infer that the result of
an addition will always be numeric, which means I have to insert extra
run-time type checking, and (b) with a custom function like
fn:add-duration-to-dateTime(xs:dateTime, xs:dayTimeDuration) you would get
implicit casting of untyped values to the expected types of the operands,
which you don't get with the overloaded + operator. But that's water under
the bridge.

Michael Kay

Current Thread