# Union and Intersect Operators

Michael Kay mike at saxonica.com
Sun Mar 16 15:28:00 PST 2008

```>    I hope this is a more vivid example.

You were given the answer already, but it appears you didn't understand it.

The operators "union" and "intersect" compare nodes by their identity, not by their value.

If I write

<a>
<b/><b/><b/>
</a>

then the three <b/> elements have different identity, and the union and intersect operators will treat them as distinct.

So

count(a/b[1] union a/b[2] union a/b[3])

will be 3, while

count(a/b[1] union a/b[1] union a/b[1])

will be 1. In the first example the three path expressions select different nodes, in the second example they select the same node.

Michael Kay
http://www.saxonica.com/

>
> <statistics>
> Showing Result: 3 / 13</statistics>
> <p>If you wish to know the facts about HEIGHT INCREASE, send
> 35c for details to TALL-UP.
> </p> <information>Source from page <pb n="4"
> xml:id="etn010001-006"/></information>
> <statistics>
> Showing Result: 6 / 13</statistics>
> <p>If you wish to know the facts about HEIGHT INCREASE, send
> 35c for details to TALL-UP.
> </p> <information>Source from page <pb n="4"
> xml:id="etn010001-006"/></information>
>
> The query I had used for the union and intersect is
>
>
>
> and the term I used is TALL. Is there something I had done
> wrong in my union and intersect expression here that makes
> the result return even though it is the already extracted
> data snippet itself because it has both head and p tags with
> the same word?
>
>
> Alice
> ======================================================
> Alice Wei
> MIS 2008
> School of Library and Information Science Indiana University
> Bloomington http://x-query.com/mailman/listinfo/talk ________________________________________
> From: 赵雷 [http://x-query.com/mailman/listinfo/talk]
> Sent: Sunday, March 16, 2008 12:50 AM
> To: Wei, Alice J.
> Cc: http://x-query.com/mailman/listinfo/talk
> Subject: Re:  Union and Intersect Operators
>
> It depends on how you define "duplicates". Nodes that are
> fn:deep-equal()?
> Or nodes that have the same string() value?
>
> According to your description, it seems that another page
> does not contain <head> nodes. So I guess you may want to
> eliminate nodes that contain the same content with <head>
> paste a more complete example to describe your requirment? Thanks.
>
> Lei
>
> On 3/15/08, Wei, Alice J. <http://x-query.com/mailman/listinfo/talk> wrote:
> > Hi,
> >
> >   Sorry, that was a typo.
> >   As for the issue with the union operator, I only want
> anything that matches that, but I don't want duplicates. For example:
> >
> >  <statistics>
> >  Showing Result: 2 / 20</statistics>
> >                         apartments—course is practically paid for!"
> >  <emph rend="italics">Adelindo Orsi, Jr., Azusa, Calif.</emph>
> >         <description>
> >  <p rend="bold">Be a LOCKSMITH Like Me/</p>
> >         <p>
> >  Add to your income with easy spare time earnings—cash in on the
> >                         nationwide shortage of skilled
> locksmiths. Quickly step into a highly paid
> >  </p>
> >                 </description>
> >         <information>Source from page <pb n="25"/>  </information>
> >
> >   I specified that I want anything that is case insensitive
> with "KEY" in there. However, since I have another group with
> similar node structure in another page as indicated in
> <information> node, the same information is presented again.
> I don't have this problem when I only run the search asking
> for only <head> containing certain text, therefore I am
> guessing it must not be the distinct-values() issue.
> >
> >  Or, is it?
> >
> >  Thanks for your help.
> >
> >
> >  Alice
> >  ======================================================
> >  Alice Wei
> >  MIS 2008
> >  School of Library and Information Science  Indiana University
> > Bloomington  http://x-query.com/mailman/listinfo/talk
> > ________________________________________
> >
> > From: 赵雷 [http://x-query.com/mailman/listinfo/talk]
> >  Sent: Friday, March 14, 2008 10:12 PM
> >  To: Wei, Alice J.
> >  Cc: http://x-query.com/mailman/listinfo/talk
> >  Subject: Re:  Union and Intersect Operators
> >
> >
> >  In your second query, "intercept" should be "intersect"?
> >
> >  Union is functioned on nodes. And two nodes nodeA and nodeB are
> > duplicates only if they satisfy "nodeA is nodeB". In the xpath
> different
> > nodes, which are not duplicates. Thus "union" gives all of
> them, and
> > "intersect" gives none.
> >
> >  Regards,
> >  Lei
> >
> >  On 3/15/08, Wei, Alice J. <http://x-query.com/mailman/listinfo/talk> wrote:
> >  > Hi,
> >  >
> >  >  I have a strange output here from the web application using
> > xquery. I intend to use the union operator here to combine all the
> > results of the possible tags I intend to run search against, but it
> > turned out that the \$count variable below, which the
> similar XPath has
> > been used to call the function as well for the query, does
> not exclude
> > duplicates. What it appears to do is giving me all the tags that
> > contain the the phrase \$search to my query  >  > let \$search :=
> > upper-case(request:get-parameter("search", ""))  > let \$count :=
> >  >
> >  > When I used
> >  >
> >  > let \$count :=
> > union p) intercept (note union
> >  >
> >  > it gives me no output.
> >  >
> >  > However, the first line I had, it gives me back as many
> times the phrase \$search has been used in the four parameters.
> >  > If anyone needs to see more of my query, I would love to
> provide it, but the query itself is very long.
> >  >
> >  > Can anyone please give me tips on what might have gone
> wrong here?
> >  >
> >  > Thanks to those who can help.
> >  >
> >  > Alice
> >  > ======================================================
> >  > Alice Wei
> >  > MIS 2008
> >  > School of Library and Information Science  > Indiana University
> > Bloomington  > http://x-query.com/mailman/listinfo/talk  >  >
> > _______________________________________________
> >  > http://x-query.com/mailman/listinfo/talk
> >  > http://x-query.com/mailman/listinfo/talk
> >  >
> >
>
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> http://x-query.com/mailman/listinfo/talk

```

### PURCHASE STYLUS STUDIO ONLINE TODAY!

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