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

Re: boolean(string(false())) is true - always?

Subject: Re: boolean(string(false())) is true - always?
From: "Sewell, David R. (drs2n) dsewell@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 2 Mar 2017 15:27:00 -0000
Re:  boolean(string(false())) is true - always?
The difference in return value between fn:boolean('false') and 
xs:boolean('false') must be in the top ten of XPath "gotcha's" -- I usually 
forget that despite having worked with XPath for more than a decade.

David

On Thu, 2 Mar 2017, Martin Honnen martin.honnen@xxxxxx wrote:

> On 02.03.2017 16:00, Michael MC<ller-Hillebrand mmh@xxxxxxxxx wrote:
>
>> <xsl:function name="dy:isFoo" as="xs:boolean">
>>     <xsl:param name="node" as="node()"/>
>>     <xsl:choose>
>>       <xsl:when test="$node[self::bar/@foo = 'x']">
>>             <xsl:value-of select="true()"/>
>>         </xsl:when>
>>         <xsl:otherwise>
>>             <xsl:value-of select="false()"/>
>>         </xsl:otherwise>
>>     </xsl:choose>
>> </xsl:function>
>> 
>> and changed that to the more elegant:
>> 
>> <xsl:function name="dy:isFoo" as="xs:boolean">
>>     <xsl:param name="node" as="node()"/>
>>     <xsl:sequence select="exists($node[self::bar/@foo = 'x'])"/>
>> </xsl:function>
>> 
>> BUT then I looked at my old code and said to myself: This could never have 
>> worked?!
>> 
>> Isn't xsl:value-of creating a text node, so in xsl:otherwise it creates 
>> 'false'. And if this is cast to boolean as the function requires, we should 
>> get true(), because the string is not empty?
>
> I think the rules lay out that the text node with 'true' or 'false' is 
> atomized to xs:untypedAtomic 'true' or 'false' and then the conversion to 
> xs:boolean is defined as a cast based on the XSD schema spec which treats 
> 'true' as the boolean value true and false as the boolean value false. So 
> what happens in language terms would be
>   'true' cast as xs:boolean
> which gives the boolean value true respectively
>   'false' cast as xs:boolean
> which gives the boolean value false and not
>   boolean('false')
> which would give the boolean value true.
>
>
> 
>

-- 
David Sewell
Manager of Digital Initiatives
The University of Virginia Press
Email: dsewell@xxxxxxxxxxxx   Tel: +1 434 924 9973
Web: http://www.upress.virginia.edu/rotunda

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.