Possible 8.7.3j bug : FORG0001 from not(not(
Added by Anonymous over 18 years ago
Legacy ID: #3870024 Legacy Poster: Inigo Surguy (inigo)
Hi, I've found what looks like a bug in Saxon-B 8.7.3j. I think the result of an XPath: not(not( [an empty nodeset] )) should be false. Instead, when I use that result in an xsl:function as="xs:boolean", I get the error: FORG0001: The string "" cannot be cast to a boolean I'm using Saxon 8.7.3j from the command line. There are three issues here: a) I don't believe this should be an error b) There's no line number reported for the problem c) Most baffling to me is that when running command line Saxon with tracing enabled, it works as I expect! It also works when using the same version of Saxon from within Oxygen. This problem can be worked around, of course: I've changed the code that was doing a not(not(xxx)) to doing an if (xxx) then true() else false(). The stylesheet attached below reproduces this problem. Cheers Inigo -- Inigo Surguy CSW Informatics Ltd. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myfn="http://surguy.net/myFunctions" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> <xsl:template match="/"> <result> <xsl:if test="myfn:isBroken(.)"><anElement/></xsl:if> </result> </xsl:template> <xsl:function name="myfn:isBroken" as="xs:boolean"> <xsl:param name="current"/> <xsl:value-of select="not(not( $current/nonExistentElement )) "/> </xsl:function> </xsl:stylesheet>
Replies (5)
Please register to reply
RE: Possible 8.7.3j bug : FORG0001 from not(n - Added by Anonymous over 18 years ago
Legacy ID: #3870197 Legacy Poster: Michael Kay (mhkay)
The expression not(not( $current/nonExistentElement )) return a boolean. The xsl:value-of then constructs a text node containing the result of converting this boolean to a string. The string value of the text node will be "true" or "false" - it really doesn't matter which. The "as = xs:boolean" on the function declaration then gets the effective boolean value of the result returned by the body of the function. The effective boolean value of a sequence containing a single text node is always true, regardless of the content of that node. So your function always returns true. Use xsl:sequence to construct the result of a function, not xsl:value-of. Michael Kay http://www.saxonica.com/
RE: Possible 8.7.3j bug : FORG0001 from not(n - Added by Anonymous over 18 years ago
Legacy ID: #3870204 Legacy Poster: Inigo Surguy (inigo)
Okay - thanks for the explanation. In that case, is it a bug that a line number wasn't reported for this error, and that it behaves differently when -T is specified to enable tracing? Cheers Inigo
RE: Possible 8.7.3j bug : FORG0001 from not(n - Added by Anonymous over 18 years ago
Legacy ID: #3870231 Legacy Poster: Michael Kay (mhkay)
The missing line number is fixed in my current build - improving diagnostics is a continuous process. The failure to perform the type checking when -T is enabled is a bit more worrying - I'll look into it.
RE: Possible 8.7.3j bug : FORG0001 from not(n - Added by Anonymous over 18 years ago
Legacy ID: #3870266 Legacy Poster: Michael Kay (mhkay)
My previous response was wrong - sorry. The text node produced by value-of should be converted to an xs:boolean using the function conversion rules, not by taking the effective boolean value. That means the text node is atomized, producing the untyped atomic value "false", which is then cast to a boolean, producing the boolean value false, and everything should work fine, if inefficiently. The trace version of the code is doing this correctly. The non-trace code is doing an incorrect optimization on the double negation: the result is that the xsl:value-of takes the string value of the path expression ("") rather than its effective boolean value (false). This optimization is inhibited (as is often the case) when trace code is compiled in. Thanks for persisting!
RE: Possible 8.7.3j bug : FORG0001 from not(n - Added by Anonymous over 18 years ago
Legacy ID: #3873017 Legacy Poster: Inigo Surguy (inigo)
Thank you! Inigo
Please register to reply