Re: [xslt] possible bug in functions



En réponse à Dan Allen <mojave@mojavelinux.com>:
> I may have discovered a bug with functions when returning boolean
> values.  Do the following test.  Create a variable as such:
> 
> <xsl:variable name="foo" select="false"/>

Even if you replace "false" with "false()", as I think you wanted to do, it 
does work, but *you*'re wrong.

$foo then is a boolean with value false.

> <xsl:if test="$foo">
>   <xsl:text>I see this as true</xsl:text>
> </xsl:if>
> 
> That works fine.

$foo is false(), OK.

> Now, write a function like this:
> 
> <func:function name="foo">    
>   <func:result>
>     <xsl:value-of select="false"/>
>   </func:result>
> </func:function>

In <http://www.exslt.org/func/elements/result/index.html> :
  The value of the func:result element is determined in a similar way to 
variable-binding elements as described in [11.2 Values of Variables and 
Parameters] of [XSLT].

So the result is a result tree fragment containing a text node with string-
value "false" (string-value of the boolean false()).

> <xsl:if test="foo()">
>   <xsl:text>I see this as true</xsl:text>
> </xsl:if>

A result tree fragment is like a node-set, and the boolean value of a node set 
is false() if the node-set is empty, true otherwise.
The RTF returned by foo() contains (by definition) a single root node, so it 
evaluates to true().

What happens if you use the following?
<func:function name="foo">
  <func:result select="false()" />
</func:function>

This function does return a boolean value.

Tom.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]