This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
[saxon] casting result tree fragment to boolean
- To: XSL mailing-list <xsl-list at mulberrytech dot com>
- Subject: [saxon] casting result tree fragment to boolean
- From: David Allouche <david at ansible dot xlii dot org>
- Date: Sun, 20 Aug 2000 03:09:01 -0200 (GMT+2)
- Reply-To: xsl-list at mulberrytech dot com
Hello,
this is another post of the same kind as the previous one, just to make
sure I am not misunderstanding XSLT:
- something works a way I don't expect it to
- is it an abnormal behavior of saxon ?
- if yes, there is a workaround
Here is the crash course:
- - - xsl-1.xsl - - -
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="flag">
<xsl:call-template name="empty"/>
</xsl:variable>
<xsl:if test="$flag">
<xsl:message>No result means true ???</xsl:message>
</xsl:if>
<xsl:if test="boolean($flag)">
<xsl:message>Even with explicit boolean cast !</xsl:message>
</xsl:if>
<xsl:if test="not(string($flag))">
<xsl:message>But no result converted to string means
false...</xsl:message>
</xsl:if>
<xsl:variable name="other-flag">
<xsl:call-template name="empty"/>
</xsl:variable>
</xsl:template>
<xsl:template name="empty"/>
</xsl:stylesheet>
- - - - - - - - - - -
- - - dummy.xml - - -
<?xml version="1.0" encoding="iso-8859-1"?>
<dummy/>
- - - - - - - - - - -
- - - shell log - - -
$ java com.icl.saxon.StyleSheet dummy.xml xsl-1.xsl
No result means true ???
Even with explicit boolean cast !
But no result converted to string means false...
<?xml version="1.0" encoding="utf-8"?>
- - - - - - - - - - -
Here is what is said in "XSLT Programmer's Reference" about converting a
result tree fragment to a boolean (p. 427)
- - - XSLT Programmer's Reference - - -
The result tree fragment is first converted to a string, and the string is
then converted to a Boolean. The resulting boolean is true if the result
tree fragment contains any non-empty text nodes, and is false otherwise.
- - - - - - - - - - - - - - - - - - - -
Once again, either I am deeply misunderstanding something, or the book and
the program are not coherent...
-- David --
PS: Is Mike Kay still reading the list ?
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list