This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Variable: true or false


Hi Tom:

This is very tricky.

Problem is, your declaration

   <xsl:variable name="selectUser"/>

isn't as "empty" as it looks. Absent a select expression, the variable 
contains a result tree fragment. XSLT (11.1) says about this special data 
type that it "is treated equivalently to a node-set that contains just a 
single root node" (going on to qualify this considerably). That is, if you 
had the declaration

   <xsl:variable name="selectUser">
       <holla/>
    </xsl:variable>

the variable $selectUser would be bound to a result tree fragment with a 
structure containing two nodes, a root and a single child (an element named 
'holla'). But yours contains just that single root.

Alas, when this is treated as a node-set containing a root for purposes of 
evaluating the boolean() function, this comes out as true().

If you'd said

  <xsl:variable name="selectUser" select="''"/>
  (setting the value to be the empty string), or

  <xsl:variable name="selectUser" select="false()"/>
  (a boolean false), or even

  <xsl:variable name="selectUser" select=""/>
  (the null expression evaluates to an empty node set),

...*then* you'd have gotten false as you expected.

This is only one reason result tree fragments are troublesome. Since they 
are also of questionable utility, rumor has it they may be invited to 
leave, disappearing from future versions of XSLT. Then you'll get an 
(empty) node set as you expected.

Cheers,
Wendell


At 09:02 PM 4/6/01, you wrote:
>I do the transform on this XSL and get "true". I would have expected
>"false".
>Thought the boolean of an empty object would always be false.
>
>Using Xerces 1.4 and Xalan 1.1
>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>version="1.0">
>    <xsl:variable name="selectUser"/>
>    <xsl:template match="/">
>       <xsl:choose>
>          <xsl:when test="$selectUser">
>             true
>          </xsl:when>
>          <xsl:otherwise>
>             false
>          </xsl:otherwise>
>       </xsl:choose>
>    </xsl:template>
></xsl:stylesheet>
>
>Tom Gilbert
>tom.gilbert@cartanova.com

======================================================================
Wendell Piez                            mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]