xsl-list
[Top] [All Lists]

[xsl] Error recovery from casting in XSLT 2.0

2007-06-19 03:47:39
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






--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>