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

Re: Coding aroung a "Cannot convert zero-length string

Subject: Re: Coding aroung a "Cannot convert zero-length string to an integer" error
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Mon, 13 Aug 2007 21:34:58 +0100
Re:  Coding aroung a "Cannot convert zero-length string
On 8/13/07, Angela Williams <Angela.Williams@xxxxxxxxxxxxxxxxxx> wrote:
> > Andrew Welch
> >So basically always type your parameters - if you're expecting a string
> that can be empty then you want:
> ><xsl:param name="foo" as="xs:string?"/>
> >...and then using test="not($foo)" should be fine.
>
> In the function below, I've typed my $xpath, but still the empty string
> was passed to saxon:evaluate and generated the 'Expected node but
> received EOF' message from Saxon.  When I changed it to check for
> string-length, I received my custom error message.
>
> Did I miss something?
>
>
>   <xsl:function name="fk:eval">
>     <xsl:param name="context" as="node()+"/>
>     <xsl:param name="xpath" as="xs:string" />
>     <xsl:param name="msg" as="xs:string" />
>
>    <xsl:choose>
>       <!-- <xsl:when test="not($xpath)"> -->
>       <xsl:when test="string-length(normalize-space($xpath)) eq 0">
>         <xsl:text> Custom error message. </xsl:text>
>       </xsl:when>
>       <!-- More code removed -->
>       <xsl:otherwise>
>         <xsl:sequence select="$context/sax:evaluate($xpath)" />
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:function>

It's almost certainly the value you are passing for the $xpath
parameter is not the empty string '' but ' ' or longer - basically a
string of white space (most likely from getting the string value of a
node in the input and getting white space text nodes)

It's a shame that xs:string('') is allowed (as in '' is considered a
valid xs:string).  In nearly all the XML Schemas I write I have to
define my own xs:non-empty-string type and use that wherever I
would've used xs:string.  I'm sure there must be a good reason for it,
but it does cause extra hassle.

Anyway, in your case I think you will after all that have to do something like:

not($xpath) or string-length(normalize-space($xpath)) eq 0

or maybe:

not($xpath) or matches($xpath, '\s')


cheers
andrew
-- 
http://andrewjwelch.com

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.