Subject: RE: [xsl] XSLT 2.0 empty string: Summary? From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Tue, 1 Mar 2005 16:33:35 -0000 |
> 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSLT 2.0 empty string: Su, Pawson, David | Thread | RE: [xsl] XSLT 2.0 empty string: Su, Pawson, David |
RE: [xsl] xslt 2. Date arithmetic., Michael Kay | Date | [xsl] Triming in XSLT, Tham Tinh |
Month |