Sorting generalized for attributes