xsl-list
[Top] [All Lists]

RE: Can I use a boolean variable in an xsl:if test

2005-02-08 12:29:48
At 10:58 AM 2/8/2005, Mike wrote:
<xsl:variable name="show">
  <xsl:value-of select = "$time != 60000" />
</xsl:variable>

is not a boolean variable, it is a result tree fragment. If you convert a
result tree fragment to a boolean, the result is always true.

The correct way to write a boolean variable is:

<xsl:variable name="show" select="$time != 60000" />

I simply have no idea why this verbose, inefficient, and often incorrect
style using <xsl:value-of> within <xsl:variable> has become so popular.

My guess is that newbies imagine xsl:value-of to be some kind of "evaluate" function. Of course what it really is, is an instruction to write a string to a result tree (to "the" result tree or to a result-tree-fragment, as the case may be). Since this is generally what we want to have happen to our results, there seems to be nothing to get confused about.

Until it breaks, that is, because we're not writing it out, but doing something else with it instead. Like testing whether it's true, while imagining we're testing the expression that was evaluated for it.

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)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
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--