Electronic speedometers can sometimes work only intermittently. The needle will swing wildly or stop working altogether. First job is to clean the connections on both ends of the connecting cable and check the continuity.
Before buying a new axle transmitter, check all +12V supply and earth connections and make sure the relevant fuse is making sound contact. There may also be an internal breakage in a wire between the transmitter and speedo, which makes intermittent contact as it vibrates.
If you can easily rig up temporary substitutes for the wires, do so before buying a new transmitter.