Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] XSLT 2.0 empty string: Summary?

From: "Michael Kay" <mike@------------>
To:
Date: 3/1/2005 4:34:00 PM
> 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent