[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Coding around a "Cannot convert zero-length string

Subject: RE: Coding around a "Cannot convert zero-length string to an integer" error
From: cknell@xxxxxxxxxx
Date: Mon, 13 Aug 2007 10:23:39 -0400
RE:  Coding around a "Cannot convert zero-length string
Very perceptive, you put your finger on it! I changed my code to use a slightly more compact version of your expression:

<xsl:function name="ck:excel-serial-date" as="xs:string?">
  <xsl:param name="input-date" as="xs:string?"/>
  <xsl:value-of select="if(not($input-date) or $input-date = '') then '' else xs:string(xs:integer(translate(xs:string(xs:date($input-date)-xs:date('1900-01-01')),'PD','')))"/>
</xsl:function>

-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Houghton,Andrew <houghtoa@xxxxxxxx>
Sent:     Mon, 13 Aug 2007 10:03:03 -0400
To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject:  RE:  Coding aroung a "Cannot convert zero-length string to an integer" error

> From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx] 
> Sent: 13 August, 2007 09:44
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.