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

two xml match/diffes

James A. Robinson jim.robinson at stanford.edu
Tue Jan 16 23:07:59 PST 2007


  two xml match/diffes
> <result>
> <same><s1>1</s1><s2>3</s2></same>
> <root1><a3>5<a3></root1>
> <root2><b2>2</b2></root2>
> </result>
> 
> How can I do this kind of query?

There is probably a better way to do this, but here is one way I came
up with.  You compute the data values common to $a and $b and then use
that to output <same/>, then you use is to figure out the non-similar
items in $a and $b:

let $a := doc('a.xml')/*
let $b := doc('b.xml')/*
let $c := $a/*[. = $b/*]
return (
  <result>{
    <same>{
      for $s at $i in $c
      return element {concat('s', $i)} {$s/data(.)}
    }</same>,
    element {node-name($a)} {
      $a/*[not(. = $c)]
    },
    element {node-name($b)} {
      $b/*[not(. = $c)]
    }
  }</result>
)

This is doing three many-to-many checks, I'm not sure how else one can
do this query, so I'd be interested in seeing what others come up with.
I'm making an assumption that the many-to-many check of something like
$b/*[not(.=$c)] is no less efficent than doing a loop performing a
per-item check of each item in $b to see if it is in $c.

Jim

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       http://x-query.com/mailman/listinfo/talk
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)


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-2007 All Rights Reserved.