Grouping of XML input with XPath 3.1 and Saxon-JS

Example input

Example XPath 3.1 code

let $comp-key := function($city) { concat($city/@country, ', ', $city/@name) }
return distinct-values(cities/city!$comp-key(.))

Example XPath results