let $comp-key := function($city) { $city/@country || ', ' || $city/@name }
return
for $key in cities/city!$comp-key(.)=>distinct-values()
return
let $group := cities/city[$key = $comp-key(.)]
return
map { $key : avg($group/@pop) }