For each person
, check the following-sibling
axis for other persons (siblings). Only check one way (not both following and preceding) to omit duplicate sibling pairs (eg. "Sabina Alfonso" and "Alfonso Sabina").
for $person in //person
for $sibling in $person/following-sibling::person
return element sibling { string-join(($person, $sibling)/@name, ',') }
For the nephews the query is quite similar, I don't think it requires further explanation:
for $aunt in //person[@gender="female"]
for $nephew in $aunt/(preceding-sibling::person, following-sibling::person)/children/person[@gender="male"]
return element AuntNeph { string-join(($aunt, $nephew)/@name, ',') }