The question

I know that many generic products, for example soap and shampoo, say "compare to product xyz" on their labels. How is this legal and when would it not be legal?