Solution:
Substituting y=0 gives f(xf(0))=f(0). If f(0)=0, the expression xf(0) takes all real values, so f is a constant function, but that does not satisfy the conditions. Therefore, f(0)=0.
Setting y=x we obtain f(0)=f(x2)−x2, i.e., f(x2)=x2. Thus, f(x)=x for all x⩾0.
Now let us substitute arbitrary x,y<0. Since then f(xy)=xy, we have f(xf(y)−yf(x))=0, which can hold only for xf(y)−yf(x)⩽0. Analogously, yf(x)−xf(y)⩽0 as well, so yf(x)=xf(y), i.e., f(x)/x=f(y)/y. It follows that f(x)=cx for all x<0, where c is some constant.
Now for x<0<y we obtain f((1−c)xy)=f(xy)−xy=(c−1)xy, i.e., f(z)=−z for z=(1−c)xy. If c=1, then f(x)≡x, which is obviously a solution. On the other hand, for c=1 we have z=0 and hence f(z)∈{cz,z}, so it must then be that c=−1, which gives the function f(x)=∣x∣ for all x. This function is also a solution: we have already checked all cases except x>0>y, and for x>0>y we have −2xy=f(−2xy)=f(xf(y)−yf(x))=f(xy)−xy=−2xy.
Therefore, the solutions are the functions f(x)=x and f(x)=∣x∣.