[xquery-talk] Xquery+ reduce two docs into one
James A. Robinson
jim.robinson at stanford.edu
Fri Jan 12 06:33:24 PST 2007
> I am quite new to xquery and I have a FLWOR question
So am I, so take this with a large grain of salt. Most of my recent
XQuery experience hasn't been at the target domain of the language,
join operations! So anyway, here is one solution (I think):
(: Get metadata from documents :)
let $m1 := doc("sebi-1.xml")/*/meta
let $m2 := doc("sebi-2.xml")/*/meta
(: determine common FileName by textual value :)
let $intersect := (
let $common := (
for $f in ($m1/FileName, $m2/FileName)
where (($f = ($m1/FileName)) and ($f = $m2/FileName))
return $f
)
return (
for $name in distinct-values($common)
return $common[. = $name][1]
)
)
return
<FF>
<meta>{
(: for each meta with an intersecting FileName :)
for $m in ($m1, $m2)
where ($intersect = $m/FileName)
return
(: return the meta elements which are not FileName :)
$m/*[not(self::FileName)],
(: return the FileName intersect :)
$intersect
}</meta>
</FF>
This returns
<?xml version="1.0" encoding="UTF-8"?>
<FF>
<meta>
<Value2>2.8</Value2>
<Value1>7.90mm</Value1>
<FileName>file7</FileName>
<FileName>file8</FileName>
<FileName>file9</FileName>
<FileName>file14</FileName>
<FileName>file15</FileName>
<FileName>file16</FileName>
<FileName>file17</FileName>
<FileName>file18</FileName>
<FileName>file19</FileName>
</meta>
</FF>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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