xsl-list
[Top] [All Lists]

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

2005-02-08 09:13:41

<!-- Don't show if time is one minute -->
<xsl:variable name="show">
  <xsl:value-of select = "$time != 60000" />
</xsl:variable>
[snip]
<xsl:if test="$show">
    <noshow><xsl:value-of select = "$show" /></noshow> </xsl:if>

</xsl:template>

Here you want:

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

Whenever you define a variable with no select statement (i.e. it has
child content) :

<xsl:variable name="show">
  ...
</xsl:variable>
 
...the variable has a type of 'tree' (result tree fragment).  What you
are doing above is testing if the tree is true or false, and a tree is
true if it is non-empty.  So, your $show variable above contains a tree
with a root node and single text node with the value 'false', which
makes it true :)

By using the select attribute the result of the expression is bound to
the variable, giving the variable a type of boolean (and not RTF) which
is what you are after.

Cheers
andrew

--~------------------------------------------------------------------
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>
--~--