{ for $highbid in doc("bids.xml")//bid_tuple, $user in doc("users.xml")//user_tuple where $user/userid = $highbid/userid and $highbid/bid = max(doc("bids.xml")//bid_tuple[itemno=$highbid/itemno]/bid) order by $highbid/itemno return { $highbid/itemno } { $highbid/bid } { $user/name/text() } }