You could do it, don't know any one who has done it
Fixing or replacing the 4.0l SOHC would be much less trouble, especially in 2004-2011 Ranger, these have the digital(HEC) dash
4.0l OHV would need a 4.0l OHV computer and its wiring harness to run it, and that's an issue with the 2004-2011 Rangers
The 2004-2011 engine computers and HEC cluster are "married" at the factory so people could no longer swap in lower mile clusters, Ford can "re-marry" them if one breaks and needs to be swapped out, not sure DIY can do it, but moot point since no 4.0l OHV computer could work with an HEC cluster
Cab wiring is also different because of the digital dash so swapping in an analog dash(2003 and earlier) would require alot of changes/rewiring
Even V8 swap runs into these same issues on the 2004-2011 Rangers
Can you do it, sure, if time and money are no object
Should you do it, no, spend the time and money on fixing or replacing the 4.0l SOHC, sell that Ranger and buy one with a 4.0l OHV
If you already have a good 4.0l OHV then sell it to fix or replace the 4.0l SOHC