Project

Profile

Help

fn:boolean

Added by Anonymous about 19 years ago

Legacy ID: #3078371 Legacy Poster: Jon (arthur_branham)

According to the XPATH 2.0 specification: The semantics of fn:boolean are repeated here for convenience: 1. If its operand is an empty sequence, fn:boolean returns false. 2. If its operand is a sequence whose first item is a node, fn:boolean returns true. 3. If its operand is a singleton value of type xs:boolean or derived from xs:boolean, fn:boolean returns the value of its operand unchanged. 4. If its operand is a singleton value of type xs:string, xdt:untypedAtomic, or a type derived from one of these, fn:boolean returns false if the operand value has zero length; otherwise it returns true. 5. If its operand is a singleton value of any numeric type or derived from a numeric type, fn:boolean returns false if the operand value is NaN or is numerically equal to zero; otherwise it returns true. 6. In all other cases, fn:boolean raises a type error. The following snippet seems to conform to condition 3 of above (note: the o:internal attribute is of type xs:boolean). I have tried making the value of it "false" and "0" and in either case the "when" clause is executed rather than the "otherwise". So the error lies in the fn:boolean not converting the value to its proper type or that the test is not evaluating the xs:boolean returned from the function correctly. <xsl:choose> <xsl:when test="${fn:boolean(/o:offers/@o:internal)}"> <xsl:text>Internal</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>External</xsl:text> <xsl:otherwise> </xsl:choose>


Replies (2)

RE: fn:boolean - Added by Anonymous about 19 years ago

Legacy ID: #3078400 Legacy Poster: Michael Kay (mhkay)

The content of the <xsl:when test=""> attribute must be an XPath expression and ${fn:boolean(/o:offers/@o:internal)} isn't an XPath expression, so you should get a syntax error. But let's assume you actually wrote <xsl:when test="fn:boolean(/o:offers/@o:internal)"> Firstly, the call on fn:boolean is redundant: it takes the effective boolean value of its argument, but the test="" does that anyway. However, even if @o:internal has been schema-validated and is annotated as a boolean, the value of the expression /o:offers/@o:internal is a sequence of nodes, and conditions 1 or 2 in the list below apply. You are testing for the existence of the attribute, not testing its value. You need to atomize the node to extract its value. The easiest way to force that is to use <xsl:when test="xs:boolean(/o:offers/@o:internal)"> This will work whether or not the document has been schema-validated. The xs:boolean constructor function expects an atomic value, so atomization is forced. If the attribute is annotated as a boolean, it is then a no-op. If the attribute is annotated as as untypedAtomic, xs:boolean does a conversion according to the schema rules, so "false" and "0" are treated as false. Michael Kay http://www.saxonica.com/

RE: fn:boolean - Added by Anonymous about 19 years ago

Legacy ID: #3079103 Legacy Poster: Jon (arthur_branham)

Ok, that makes sense, I was thinking that an attribute is an atomic value, although i see now that it is listed under the hierarchy of node types. Thanks for your help.

    (1-2/2)

    Please register to reply