[xsl] Coding aroung a "Cannot convert zero-length string to an integer" error

Subject: [xsl] Coding aroung a "Cannot convert zero-length string to an integer" error
From: cknell@xxxxxxxxxx
Date: Mon, 13 Aug 2007 09:44:24 -0400
<xsl:function name="ck:excel-serial-date" as="xs:string?">
  <xsl:param name="input-date" as="xs:string?"/>
  <xsl:value-of select="if($input-date = '') then '' else xs:string(xs:integer(translate(xs:string(xs:date($input-date)-xs:date('1900-01-01')),'PD','')))"/>
</xsl:function>

This is a function I wrote (am writing?) to compute an integer that represents the a date to Excel 2000.

There may or may not be a value in the input document that corresponds to a cell in the output. In that case, I want the function to return an empty string.

So you can see here that I tell the function to expect a string, and that an empty string (zero-length string) is acceptable input.

I also tell it that it should return a string, and that a zero-length string is acceptable output.

In the body of the function, I state that if the input is a zero-length string, it should return a zero-length string, otherwise it is to compute the number of days between January 1, 1900 and the input date, convert the result to a string, and return that.

Anyway, that's what I thought I was doing, but when I attempt a transformation, I get the following error message:

"Fatal Error! Cannot convert zero-length string to an integer"

I thought that this fragment "if($input-date = '') then '' ..." would short-circuit any attempt to convert a zero-length string to an integer, but apparently I have misapprehended something key here. Can anyone point out where I've gone wrong and suggest a fix?

Thanks.

-- 
Charles Knell
cknell@xxxxxxxxxx - email

Current Thread