[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Incorrect Intersect and Except Output?

Florent Georges lists at fgeorges.org
Sat Mar 29 15:36:23 PST 2008


  Incorrect Intersect and Except Output?
"Wei, Alice J." wrote:

> let $a :=
>
collection("xmldb:exist://db/cbm")//ad//address[contains(upper-case(.),$search)],
> $c :=
>
collection("xmldb:exist://db/cbm")//ad//address[contains(upper-case(.),$search2)],

> [...]

> $a intersect $c

  If you want to apply two predicates to the same nodes, why don't do
it simply and explicitely:

    collection("xmldb:exist://db/cbm")//ad//address
      [contains(upper-case(.),$search)]
      [contains(upper-case(.),$search2)]

  Or even better to encapsulate the predicate and avoid duplicate
upper-casing of whole element's text value:

    declare function local:my-predicate(
        $elem as element(),
        $str1 as xs:string,
        $str2 as xs:string
      )
      as xs:boolean
    {
      let $v := upper-case($elem)
        return
          contains($v, $str1) and contains($v, $str2)
    }

    collection("xmldb:exist://db/cbm")//ad//address
      [local:my-predicate(., $search, $search2)]

or for variable number of search strings:

    declare function local:all-true($b as xs:boolean+)
      as xs:boolean
    {
      empty($b[not(.)][1])
    }

    declare function local:my-predicate(
        $elem as element(),
        $strs as xs:string+
      )
      as xs:boolean
    {
      let $v := upper-case($elem)
        return
          local:all-true(
            for $s in $strs return contains($v, $s))
    }

    collection("xmldb:exist://db/cbm")//ad//address
      [local:my-predicate(., ($search, $search2))]

  Not tested.

  Regards,

--drkm
























      _____________________________________________________________________________ 
Envoyez avec Yahoo! Mail. Plus de moyens pour rester en contact. http://mail.yahoo.fr



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.