xsl-list
[Top] [All Lists]

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

2007-08-13 07:03:27
From: cknell(_at_)onebox(_dot_)com [mailto:cknell(_at_)onebox(_dot_)com] 
Sent: 13 August, 2007 09:44
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Coding aroung a "Cannot convert zero-length 
string to an integer" error

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

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?

I think the issue is that an empty string is not the same as a
non-existent node.  You might need to change the test to:

if(not(exists($input-date)) or normalize-space($input-date) = '')

although you might be able to shorten it to:

if (normalize-space($input-date) = '')


Andy.

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