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

RE: Boolean true() and false() as strings?

Subject: RE: Boolean true() and false() as strings?
From: "John E. Simpson" <simpson@xxxxxxxxxxx>
Date: Fri, 06 Oct 2000 12:18:46 -0400
boolean true
At 08:52 AM 10/06/2000 +0100, Kay Michael wrote:
> A curious thing (well, to me!)... consider this template rule:

The <xsl:value-of> converts the booleans to strings; and the use of
xsl:variable with content creates a result tree fragment containing this
string as a child node. So you are quite right, test="$units_gt_300" would
always succeed, because it is testing whether the node-set equivalent to the
RTF contains any nodes: converting an RTF to a boolean always returns true
(despite what my book says on page 81 [sorry!].

But why don't you just write
<xsl:variable name="units_gt_300" select="units &gt; 300"/>
That way you get a variable whose type is boolean.

*That* is exactly what the doctor ordered. Thanks, Mike!


I couldn't use a simple select="true()" because the value would be either true() or false() depending on conditions in the template rule. So I'd made what is possibly a typical procedural programmer's mistake and wrapped up the whole thing in an xsl:choose block, a la if-then-else. But Mike's solution above is much neater (in all senses of the word)... not to mention that it actually works. :)

(And thanks, too, to Wendell and Evan for their characteristically clear takes on why this happens.)

==========================================================
John E. Simpson | "Curiosity killed the cat,
http://www.flixml.org | but for a while I was a
XML Q&A: http://www.xml.com | suspect." (Steven Wright)



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.