Welcome to TRS
There were two different Ford 4.0l engines used in 1997.
4.0l OHV used from 1990 to 2000
4.0l SOHC used from 1997 to 2012
The engines are unrelated except for both being 4 liter displacement, so few related parts
Rangers all used only the 4.0l OHV from 1990 to 2000
Explorers could have either from 1997 to 2000
In 2001 all Rangers(and Explorers) got the 4.0l SOHC and had it until 2012, end of the Ranger model
To answer the question, yes, a '97 4 litre will bolt to an engine bay and trans after '01 4 litre is removed.
4.0l OHV and SOHC engines used same motor mounting spot and had the same trans bolt pattern, but computer control and engine wiring are not the same