Implement uniqueSort

This method is useful for code that needs to operate based on the
document order of the generated nodes.