[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: date calculations

Subject: RE: date calculations
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 26 Mar 2007 09:50:14 +0100
RE:  date calculations
> > 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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.