[Fwd: Re: Boolean or not Boolean ?]

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Fwd: Re: Boolean or not Boolean ?]

golgoth14@nonlimit.ch
Please, have a look on my example:

for $element in (/pd:folder)
return
  <r id="{$element/@id}">
   <c1>
   {
       
(fn:exists($element/pd:organisations/pd:organisation[./pd:organisationId/@idRef
eq "ORGANISATIONGROUP-000000014"]/pd:dateFrom/@xsi:nil))
          or
xs:boolean(($element/pd:organisations/pd:organisation[./pd:organisationId/@idRef
eq "ORGANISATIONGROUP-000000014"]/pd:dateFrom le "2005-10-26"))
   }
   </c1>
   <c2>
   {
       
(fn:exists($element/pd:organisations/pd:organisation[./pd:organisationId/@idRef
eq "ORGANISATIONGROUP-000000014"]/pd:dateTo/@xsi:nil))
          or
xs:boolean(($element/pd:organisations/pd:organisation[./pd:organisationId/@idRef
eq "ORGANISATIONGROUP-000000014"]/pd:dateTo ge "2005-10-26"))
   }
   </c2>
   <c1_AND_c2>
   {
       
((fn:exists($element/pd:organisations/pd:organisation[./pd:organisationId/@idRef
eq "ORGANISATIONGROUP-000000014"]/pd:dateFrom/@xsi:nil))
          or
($element/pd:organisations/pd:organisation[./pd:organisationId/@idRef eq
"ORGANISATIONGROUP-000000014"]/pd:dateFrom le "2005-10-26"))
   and
       
((fn:exists($element/pd:organisations/pd:organisation[./pd:organisationId/@idRef
eq "ORGANISATIONGROUP-000000014"]/pd:dateFrom/@xsi:nil))
          or
($element/pd:organisations/pd:organisation[./pd:organisationId/@idRef eq
"ORGANISATIONGROUP-000000014"]/pd:dateFrom le "2005-10-26"))
   }
   </c1_AND_c2>
  </r>

The result is :
<r id="FOLDER-000000002">
   <c1>true</c1>
   <c2>false</c2>
   <c1_AND_c2>true</c1_AND_c2>
</r>

But, the fn:exists() returns a xs:boolean and the result of a
comparaison (le, ge operators) is also a xs:boolean.
Why the result of c1 and c2 condition is a xs:string instead a xs:boolean ?

Strange no ?

St├ęphane


Pierrick Brihaye wrote:

> Golgoth 14 wrote:
>
>> let $a := "true"
>> let $b := "false"
>> return $a and $b
>>
>> why this query returns true ???
>
>
> Because :
>
> you evaluate the *effective boolean values* of two strings
> - both these effective boolean values are true
> -- since the strings haven't a zero length
>
> See http://www.w3.org/TR/xpath20/#id-ebv
>
>> when a logic operator is used, the result must be a boolean
>
>
> It is.
>
>> and the values ($a and $b) must be cast to boolean
>
>
> No. It is their effective boolean value that is taken in consideration.
>
> See http://www.w3.org/TR/xpath20/#id-logical-expressions
>
> What you want is probably close to this :
>
> let $a := "true"
> let $b := "false"
> return $a instance of xs:boolean and $b instance of xs:boolean
>
> Cheers,
>



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open