Re: [xsl] An empty sequence is not allowed as the first argument ...

Subject: Re: [xsl] An empty sequence is not allowed as the first argument ...
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 02 Jun 2006 17:48:08 -0400
Charles,

Mike will probably have the definitive answer on this one. Given how it's now late on Friday over in the UK, however, I'll take a guess.

How about having a wrapper function that will accept any argument or none, and does type-checking on it before calling your actual formatting function? XPath 2.0 has the "castable as" operator to help with this kind of thing.

In a simple case, you could declare your function's argument (parameter) as "xs:string?" or "element(date)?" or whatever, to allow for a missing argument, and then trap that condition.

In my XSLT 2.0 dates processing (which like yours, doesn't assume schema-validity) I have a function that assigns a date of Jan 1, year 1 to things that aren't properly dated (which means "things my code can't make a date out of"). It's something of a kludge, since I have to assume I'll never need the date 0001-01-01 for real. (It's a timesheet application, so this is not unfair.) Later in the application such undated dates get caught, so as not to be treated like my "real" dates. I'd love to know from an actual programmer how better to do this in XSLT.

Cheers,
Wendell

At 04:02 PM 6/2/2006, you wrote:
I've written an XSLT function to format dates fetched from a database. This worked well until I pulled some records with NULL values for the date I wished to format. When my stylesheet encountered this element, Saxon emitted this error message and ended with a fatal error:

Fatal Error! An empty sequence is not allowed as the first argument of ck:std-date-string-fmt()

You may well ask, "What did you expect?" The answer is that I was not expecting anything. I was happily ignorant of the lurking danger. I tried to supply a default empty string value for the parameter that causes the function to choke when no value is supplied, only to be upbraided by Saxon telling me that default values are not permitted in function parameters.

(I had slipped in an xsl:choose to catch the empty-sting cases, but without being able to assign a default value, that failed.)

Does an empty sequence have some kind of xs:type that I could cast to an xs:string, and if so, how is it done? If not, how do I handle cases when no data comes from my database?
--
Charles Knell
cknell@xxxxxxxxxx - email

Current Thread