Re: [xsl] Variable: true or false

Subject: Re: [xsl] Variable: true or false
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 06 Apr 2001 16:52:09 +0100
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">

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.


At 09:02 PM 4/6/01, you wrote:
I do the transform on this XSL and get "true". I would have expected
Thought the boolean of an empty object would always be false.

Using Xerces 1.4 and Xalan 1.1

<xsl:stylesheet xmlns:xsl="";
   <xsl:variable name="selectUser"/>
   <xsl:template match="/">
         <xsl:when test="$selectUser">

Tom Gilbert

====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 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:

Current Thread