[Home] [By Thread] [By Date] [Recent Entries]
On 31/05/2023 13:13, Christophe Marchand cmarchand@xxxxxxxxxxxxxx wrote:
I've also found xs:boolean(number($s)) is working correctly. I would strongly suggest that you use the $s castable as xs:double construct rather than this one. As has been pointed out it fails for s="0", as the boolean value of a zero is false. But you've also been somewhat misled by getting correct answers with e.g.s="A string". The definition of number() (https://www.w3.org/TR/xpath-functions-31/#func-number) shows that when supplied with a string which cannot be parsed as a number, in most circumstances rather than failing, it returns NaN (not a number), whose boolean value is then taken as false. When you wish to check whether something can be cast to a given type using the castable as operator (https://www.w3.org/TR/xpath-31/#id-castable) is much preferable, and much clearer. John Lumley
|

Cart



