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

RE: Using or ignoring Types in XSLT 2.0 / XPath 2.0

Subject: RE: Using or ignoring Types in XSLT 2.0 / XPath 2.0
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 15 May 2003 14:01:20 +0100
xpath xs datetime
> To whit, using xs:dateTime.  In order to utilize functions on 
> this datatype in both validating and non-validating 
> environments without the danger of an unrecoverable run-time 
> error, I must:
> 
> 10  test whether datapoint is appropriately type annotated
> 20  if yes, go to 60
> 30  if no, test whether data is castable as xs:dateTime
> 40  if yes, cast and go to 60
> 50  if no, resort to string pfaffing or throw error
> 60  fn()
> 
Not so. If you have an attribute @dob whose string value is a date, but
you aren't sure whether it is annotated as a date or not, then you can
simply do:

   format-date(xs:date(@dob), "[D] [Mn] [Y]")

If you want something other than a failure in the case where @dob is an
invalid date, you can do:

  if (@dob castable as xs:date)
    then format-date(xs:date(@dob), "[D] [Mn] [Y]")
    else "** invalid date of birth **"

> For all the safety the proposed typing regime provides 
> against delivering or receiving nonsense, it has a negative 
> impact on coding efficiency if that code must work within 
> both validating and non-validating environments alike.
> 
> Let me say I would like very much to be wrong about this.  

I think you are wrong, for two reasons. Firstly, in most cases code
written to handle unvalidated documents will still work when the
documents are validated (the main case that needs care is list-valued
attributes). Secondly, I don't think this scenario, where you don't know
in advance whether the documents are validated, is very plausible. We
have yet to see how products handle this, but I suspect most products
won't validate a document unless you specifically ask them to.

Michael Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.