<result>
{
for
$doc in doc("doc.xml")/doc,
$a in $doc/a/row,
$b in $doc/b/row,
$c in $doc/c/row,
$d in $doc/d/row
where
$d/aa/text() = $a/aa/text() and
$d/dd/text() = $b/dd/text() and
$b/cc/text() = $c/cc/text()
return
<e>
{$d/dd}
{$d/ddd}
{$d/dddd}
{$d/ddddd}
{$a/aaa}
</e>
}
</result>
But I do, of course, get multiple results. What I can't work out is how to filter out distinct results, after all the 'joins' have been done in the where section. Can anyone help me out?