[xquery-talk] XQuery quirk of the day

Florent Georges lists at fgeorges.org
Sat Apr 14 06:32:54 PDT 2012


Andrew Welch wrote:

  Hi Andrew,

> normalize-space($str)

> will return true only if the string contains some none white space
> characters, so empty string '' empty sequence () and whitespace only
> ' ' will all return false.

  More precisely, the function will return a string of length zero for
each of those cases, the effective boolean value of which (e.g. when
used in the condition clause of an if instruction) is false.

    normalize-space(())
      ==> ''

    normalize-space('')
      ==> ''

    normalize-space('   ')
      ==> ''

    fn:boolean('')
      ==> false

    fn:boolean('  ')
      ==> true

    if ( C ) then T else F
    if ( fn:boolean(C) ) then T else F
      >> both are equivalent

    if ( '' ) then 1 else 0
      ==> 0

    if ( '  ' ) then 1 else 0
      ==> 1

  Regards,
 
-- 
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/



More information about the talk mailing list