At 2010-12-09 10:19 -0500, Gnana Thomas Arockiam wrote:
>Team,
>I have following two xmls,
>
>\test\BookCatalog.xml
>
><catalog>
><book id="101">
>  <author>Gambardella, Matthew</author>
>  <title>XML Developer's Guide</title>
></book>
>
><book id="102">
>  <author>Ralls, Kim</author>
>  <title>Midnight Rain</title>
></book>
></catalog>
>  \test\NewBookCatalog.xml
><catalog>
><book id="101">
>  <author>Gambardella, Matthew</author>
>  <title>XML Developer's Guide</title>
></book>
>
><book id="103">
>  <author>Corets, Eva</author>
>  <title>Oberon's Legacy</title>
></book>
></catalog>
>
>  While I use the set operations intersect, difference, union on 
> book tags of these two xmls I am not getting the desire output. I 
> was expecting a result
>set which contain the book tag with id "101" while doing an 
>intersection operation. I tried in the following way which gave me 
>the empty sequence as
>result
>
>let $a := doc("\test\BookCatalog.xml")/catalog/book
>
>let $b := doc("\test\NewBookCatalog.xml")/catalog/book
>
>return
>
>$a intersect $b
>
>Please let me know if I can achieve the desired output sequences 
>using set operations

It is a common misconception in the classroom that set operations act 
on the value of nodes, which is not the case.  Set operations act on 
the identity of nodes.  You are asking for the intersection of two 
mutually-exclusive sets, which of course would be the null set 
because they are mutually exclusive.

So you need a test that is structure/value based and not identity based.

I hope the example below helps.

. . . . . . . . . Ken

t:\ftemp>type BookCatalog.xml
<catalog>
<book id="101">
  <author>Gambardella, Matthew</author>
  <title>XML Developer's Guide</title>
</book>

<book id="102">
  <author>Ralls, Kim</author>
  <title>Midnight Rain</title>
</book>
</catalog>

t:\ftemp>type NewBookCatalog.xml
<catalog>
<book id="101">
  <author>Gambardella, Matthew</author>
  <title>XML Developer's Guide</title>
</book>

<book id="103">
  <author>Corets, Eva</author>
  <title>Oberon's Legacy</title>
</book>
</catalog>

t:\ftemp>xquery thomas.xq
<?xml version="1.0" encoding="UTF-8"?>
<book id="101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
</book>
t:\ftemp>type thomas.xq
let $a := doc("BookCatalog.xml")/catalog/book

let $b := doc("NewBookCatalog.xml")/catalog/book

return

$a [ some $book in $b satisfies deep-equal($book, .) ]

t:\ftemp>



--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:[email protected]
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to