[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
Sat Jan 13 09:55:04 PST 2007


  Xquery+ reduce two docs into one
 
> That's really great. Still I cannot use David's last version, but
> maybe it is my fault. Anyway thank you both a lot. I was already
> wondering what is going on with my machine, but now finallly it
> worked.

I wonder if the solution David sent isn't working because of some mismatch
between specifications?  If an older platform perhaps doesn't support
something new in the spec his code is taking advantage of?

I really liked how concise his code was, but I have to admit I am having
a hard time wrapping my head all the way around it.  This is my guess,
and I wonder if maybe someone could say yay or nay to it:

  The 2nd line selects all meta from the first document which are also in
  the 2nd document. It then appears to do something very clever looking,
  I think the trailing slash at the end of line 2 and '(' and line 3 is
  continuing the selection, making  it a continuation of the XPath
  selection.

  If I'm right, then within each selected meta of the first doc, he
  sets $f to be the FileName set.  Given that set he returns a similar
  expression to the 1st, where he uses another XPath selection to
  perform the final join between values.

A DBA friend of mine (who *just* took a class in XQuery from Mr. Hunter)
gave me his solution to the problem:

for $s1 in doc("sebi-1.xml")/*/meta
for $s2 in doc("sebi-2.xml")/*/meta
let $a :=  $s1/FileName[.=$s2/FileName]
where ($a)
return
  <meta>
     {$s2/Value1}
     {$s1/Value2}
     {$a}
  </meta>
(: Harv Galic :)

To me this is a very good and readable solution, it is much more like
the traditional RDBMS join.  It still requires a few code changes to
add support for a new document, but it would be a straightforward thing.
For example, if we had a 3rd document with a Value3 in it:

for $s1 in doc("sebi-1.xml")/*/meta
for $s2 in doc("sebi-2.xml")/*/meta
for $s3 in doc("sebi-3.xml")/*/meta
let $a :=  $s1/FileName[.=$s2/FileName]
let $b :=  $s1/FileName[.=$s3/FileName]
where ($a and $b)
return
  <meta>
     {$s2/Value1}
     {$s1/Value2}
     {$s3/Value3}
     {$a}
  </meta>

I think this is a happy compromise between readable code and being
able to extend it to support new documents.

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.