[xsl] "castable as" explanation

Subject: [xsl] "castable as" explanation
From: cknell@xxxxxxxxxx
Date: Mon, 28 Aug 2006 10:48:10 -0400
I'm using Saxon 8.7.1J.

I have output from a database in the form of an XML document that I transform using XSLT. As an expediant, the persons in responsible positions decided to encode data in a text field in order to accomplish a goal rather than wait until the application and database are upgraded.

Some records will contain this "packed" information and others will not. I need to determine if an element in the output XML document contains the packed information or does not, and process each type differently.

One of the data items packed into this text field is a date. I have substringed the text so as to construct a date (YYYY-MM-DD) if there is indeed a date encoded in the field.

I thought to use "castable as" in order to distinguish between those fields containing the packed information and those that do not. Here the relevant section of my stylesheet:

<xsl:variable name="is-date" select="if(DATE_PACKED_XSD castable as xs:date) then '1' else('0')" />

  <xsl:when test="$is-date = '1'">
    ... some processing here  
    ... some different processing here   

What I expected to happen was that when the stylesheet processed a DATE_PACKED_XSD element that could not be cast as a date ($is-date = 0), processing would pass to the <xsl:otherwise> branch.

What did happen was this:

stylesheet.xslt:423: Fatal Error! Invalid date "208 2-01-1 2". Non-numeric component

What am I misapprehending about "castable as"?

Charles Knell
cknell@xxxxxxxxxx - email

Current Thread