xsl-list
[Top] [All Lists]

RE: [xsl] date calculations

2007-03-26 01:50:29

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
writing:

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

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

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
http://www.saxonica.com/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--