How do you identify duplicate values in a numerical sequence using XPath 2.0?

I have an XPath expression which provides me a sequence of values like the one below: 1 2 2 3 4 5 5 6 7 This is easy to convert to a sequence of unique values 1 2 3 4 5 6 7 using distinct-values().