declare option saxon:output "indent=yes"; { for $rich_person in //person where sum($rich_person//pets:price) gt 100000 or sum($rich_person//devs:price) gt 150000 return { sum($rich_person//pets:price) } { sum($rich_person//devs:price) } }