{ ( for $movie in doc("..\..\..\examples\sourceA.xml")/sourceA/movie return {$movie/title} {$movie/director} { ( for $actA in $movie/actors/actor return $actA ) union ( let $B := doc("..\..\..\examples\sourceB.xml")/sourceB for $actB in $B/actor where $actB//title = $movie/title and not(exists( for $actA in $movie/actors/actor where $actA = $actB/name return $actA )) return {data($actB/name)} ) } ) union ( let $B := doc("..\..\..\examples\sourceB.xml")/sourceB for $titleB in distinct-values($B//title) let $dirB := $B//movie[title=$titleB]/director where not(exists( for $A in doc("..\..\..\examples\sourceA.xml")/sourceA for $titleA in $A//title where $titleA = $titleB return $titleA )) return {$titleB} {$dirB[1]} { for $actB in $B/actor where $actB//movie/title = $titleB return {data($actB/name)} } ) }