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

RE: Error recovery from casting in XSLT 2.0

Subject: RE: Error recovery from casting in XSLT 2.0
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 19 Jun 2007 12:08:50 +0100
RE:  Error recovery from casting in XSLT 2.0
There's a function error() that you can use for this purpose.

Michael Kay
http://www.saxonica.com 

> -----Original Message-----
> From: Fraser Crichton [mailto:fc@xxxxxxxxxxxxxxxxxxxx] 
> Sent: 19 June 2007 11:47
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Error recovery from casting in XSLT 2.0
> 
> Hi, there,
> 
> I'm new to XSLT 2.0 and have a question about recovering from 
> casting errors, say for instance I'm trying to cast to a 
> date, I'd do something like -
> 
>    <xsl:function name="f:castToDate" as="xs:date">
>         <xsl:param name="date-string" as="xs:string"  />
>                       
>         <xsl:sequence select="if ($date-string castable as xs:date)
>         then xs:date($date-string)
>         else if ($date-string castable as xs:dateTime)
>         then xs:date(substring-before($date-string,'T'))
>         else()" />
>     </xsl:function>   
> 
> What I'm wondering is how do I raise some kind of error in the final
> else() if the function gets passed something it can't cast? e.g.
> 
>    <xsl:function name="f:castToDate" as="xs:date">
>         <xsl:param name="date-string" as="xs:string"  />
>                       
>         <xsl:sequence select="if ($date-string castable as xs:date)
>         then xs:date($date-string)
>         else if ($date-string castable as xs:dateTime)
>         then xs:date(substring-before($date-string,'T'))
>         else("NASTY ERROR CAN'T BE RETURNED BECAUSE I'M A DATE")" />
>     </xsl:function>   
> 
> Or do I have to write another wrapper function? I'm only a 
> few hundred pages into the first of Mr Kay's books so forgive 
> me if this is a bit basic.
> 
> Cheers,
> 
> Fraser

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.