[xquery-talk] Xquery+ reduce two docs into one

James A. Robinson jim.robinson at stanford.edu
Sat Jan 13 09:55:04 PST 2007

> 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

  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)
(: 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)

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


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       jim.robinson at stanford.edu
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)

More information about the talk mailing list