The M5OD's all have integrated bell housings so each was engine specific
M5R2 was used from 1988 thru 2008
M5R1 1988 thru 2011
The 1997-2003 M5R2s from a 4.2l V6 had same bolt pattern as 5.0l OHV
And its shifter was in the same place as a Ranger's M5R1
Earlier M5R2s for the 5.0l OHV in full size trucks had shifter farther forward, stick would hit the Ranger dash in 1st, 3rd, and 5th, but shifter arm could be heated and bent, need a custom made floor plate as well
But as far as I know the M5R2 output shaft was machined to use a Drive speedometer gear in all years, the tail shaft housing just was not drilled and tapped for the speedo/VSS after 1994, could be 1993
So if you got the later model M5R2 you could add the drive gear and older tailshaft housing
You 1997 M5R1 speedo/VSS driven unit should fit, I think there was only the one size of these combo units on manual or automatics, Rangers or full size, Ford cars as well
But worst case you can get a Dakota Digital SGI-100BT, seen here:
https://www.dakotadigital.com/index.cfm/page/ptype=product/product_id=1192/mode=prod/prd1192.htm
$115
You can then use the VSS on rear axle or OSS on top rear of transmission to make the 8,000PPM AC signal the speedo, cruise, and computer need in a 1997 Ranger
Rear axle ABS runs 25,000ppm, OSS 32,000ppm the 100BT converts that to 8,000ppm, the Ford standard Pulse Per Mile
Also allows easier calibration for changes in tire size, if that matters