xsl-list
[Top] [All Lists]

RE: XSLT 2.0 empty string: Summary?

2005-03-01 09:33:35

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/



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>