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

RE: XSLT 2.0 empty string: Summary?

Subject: RE: XSLT 2.0 empty string: Summary?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 1 Mar 2005 16:33:35 -0000
xsl not equal empty string
> Consider the following code:
> 
> <xsl:variable name="foo" select="nothing" as="xs:string?"/>
> 	
> <xsl:choose>
> 	<xsl:when test="$foo != ''">A</xsl:when>
> 	<xsl:when test="$foo = ''">B</xsl:when>
> 	<xsl:when test="not($foo != '')">C</xsl:when> </xsl:choose>
> 
> When there isn't a <nothing> element, the output is C.  That is:
> 
> $foo != '' is false
> 
> and
> 
> $foo = '' also is false 
> 
> Which is strange.  If I do "$foo is empty" then Saxon tells 
> me $foo is a string and not a nodeset.

The XPath 2.0 type system is a generalization of the 1.0 system. In 1.0,
strings, numbers and booleans could exist only in the singular, whereas
nodes could exist only in the form of a node-set (a single node was treated
as a set with one member). In 2.0, everything is a sequence. So the XPath
1.0 rule for a node-set $n that ($n = '') is true if there is at least one
node in $n whose string-value is $n, has been generalized so that for a
sequence of strings $s, ($s = '') is true if any string in $s.

$foo is a sequence of strings, which may contain either no strings or one
string. ($foo = '') is therefore true if $foo contains a string and that
string is equal to ''. ($foo != '') is trus if $foo contains a string and
that string is not equal to ''. 

It might be strange, but it's a logical extension of the XPath 1.0 rules.
And as it happens the results correspond very closely (though not exactly)
to the way null values work in SQL: in SQL, if a column foo of a table row
is null, then neither (SELECT ... WHERE foo='') nor (SELECT ... WHERE foo !=
'') will select that row.

Michael Kay
http://www.saxonica.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.