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

Xquery+ reduce two docs into one

James A. Robinson jim.robinson at stanford.edu
Fri Jan 12 11:49:49 PST 2007


  Xquery+ reduce two docs into one
 
> Hello - The result was just one empty meta element. Something like
> this:
> 
> <FF>
>     </meta>
> </FF>

That's strange, I got the right results when I ran his solution. Are
you sure you updated the filenames properly?

I thought that solution looked pretty good, though the thing that
irritated me (other than the multiple many-to-many operations) was the
fact that we were both limiting ourselves to 2 input documents.

A slightly extended version that I think will work if one needs to
add new documents would be something that understands the concepts
behind the fn:collection() function. But anyway, I hope others can
point out if there is a way to do this without multiple many-to-many
type joins (which I think both David and my solution require).

declare namespace f="uri.local-functions";

(: simulate a DB where we have a collection() function and indicies :)
declare function f:collection() {
  (doc("sebi-1.xml"), doc("sebi-2.xml"))
};

(: count the number of documents :)
let $total          := count(f:collection())
(: load all metadata :)
let $meta           := f:collection()/*/meta
(: find unique filenames in all metadata  :)
let $files          := distinct-values(f:collection()/*/meta/FileName)
(: find all filenames which are in all metadata :)
let $file_intersect := (
  for $f in $files
  return (
    let $meta := f:collection()/*/meta[FileName = $f]
    where (count($meta) = $total)
    return $f
  )
)
(: find all metadata with the intersecting files :)
let $meta_intersect := (
  for $m in $meta[FileName = $file_intersect]
  return
    $m/*[not(self::FileName)]
)
(: and return the new document :)
return (
  <FF>
   <meta>{
     
     for $m in $meta_intersect
     order by local-name($m)
     return $m,
     
     for $f in $file_intersect
     return <FileName>{$f}</FileName>

   }</meta>
 </FF>
)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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.