Foaming oil is usually caused by air entering the suction side of the transmission charge pump. (Cavitation)
This can be due to loose hose clamps, hard suction hoses, the suction screen housing seals leaking, worn/hard pump seals, worn pump.
When the fault is with the hoses or suction screen, they usually leak oil while the machine is parked.
If the pump is not too badly worn, it can be resealed, if it is showing wear in the gears, body & end plates - time for a new pump.