Altova Mailing List Archives


RE: [xsl] XPath 2.0: Problems with the two boolean constants true and false

From: "Michael Kay" <mhk@--------->
To:
Date: 10/5/2003 3:31:00 PM
> 
> I see two problems with the boolean constants true and false:
> 
>   1. They cannot be used in an XPath expression -- cannot be 
> distinguished from child::true and child::false

There are no constants "true" and "false". As in XPath 1.0, the truth
values are represented by the function calls true() and false(). No
change here from 1.0.
> 
>   2. boolean('false') is true.  This is especially confusing 
> and may be the source of many programmers' headaches.

Again, no change here from 1.0. I haven't seen this cause much problem
in practice, though the introduction of xs:boolean alongside
[fn:]boolean may be confusing. xs:boolean() uses the schema rules: '0'
and 'false' give false, '1' and 'true' give true, any other string is an
error.
> 
> Because of these I chose in my code to use functions 
> returning xs:integer (0 and 1) and for templates to write 
> code like the following:
> 
>   <xsl:template name="And" match="*[namespace-uri()='allTrue-And']">
>     <xsl:param name="arg1"/>
>     <xsl:param name="arg2"/>
>          <xsl:value-of select="number(number($arg1) and 
> number($arg2))"/>
>   </xsl:template>
> 
> Am I wrong? Is there a way to overcome the above problems?
> 

It seems odd to me to use numbers instead of booleans because you don't
like the string-to-boolean conversions. If you don't like the
string-to-boolean conversions just don't use them; you can still use
booleans!

Michael Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.