[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Variable: true or false

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

====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx 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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.