[xquery-talk] Using Union/Intersect to Combine Two User-Defined Function Results

Wei, Alice J. ajwei at indiana.edu
Tue Mar 25 17:19:32 PST 2008

From: Jonathan Robie [jonathan.robie at redhat.com]
Sent: Tuesday, March 25, 2008 4:40 PM
To: Wei, Alice J.
Cc: talk at x-query.com
Subject: Re: [xquery-talk] Using Union/Intersect to Combine Two User-Defined Function Results

Wei, Alice J. wrote:
> To answer your question, each of my local:searchresult functions as something like local:searchresult((collection("my")//ad/p[contains(upper-case(.),$search)])
>   is a self efficient XML document with several nodes within it. Each of the output is something like:
> <ad>
> <head type="main">
> <emph rend="red">FREE</emph>
> </head>
>         <p>Thousands of users actual decals for a 2 deuce coupe! You'll receive free
>                         over 100 different. use on your bike, model car, van, plane, or on glass
>                         painted surfaces, metal, plastic, etc. </p>     </ad>

Does local:searchresult() create new nodes? Each of these nodes will
have a new ideintity.

> What I am trying to do here is to combine both of the result sets into one.
> Therefore, if a user intends to see the output of a search term and another term, he would only see the combined result.
> Would you say this is possible?

You can certainly do something like this:

let $a := collection("my")//ad/p[contains(upper-case(.),$search,
$b := collection("your")//ad/p[contains(upper-case(.),$search,
$c := collection("my")//ad/p[contains(upper-case(.),$search2,
$d := collection("your")//ad/p[contains(upper-case(.),$search2
local:searchresult( $a intersect $b intersect $c intersect $c )

By separating search from construction, you can rely on the identity of
the original nodes.

Hope this helps!

This last one really did the trick. Thanks!


More information about the talk mailing list