{ for $office in distinct-values(doc ('data.xml')/persons/person/office/text()) return { {$office} } { for $najemnik in doc('data.xml')/persons/person where $najemnik/office/text() = $office return { $najemnik/name/text() } } }