Ii can be done. Mechanically it would be just like doing the swap on a 1998-2001 Ranger, Lots of differences electrically, many outlined in the link below to our tech article on these swaps in general.
https://www.therangerstation.com/tech/swapping-an-explorer-5-0l-in-to-a-1998-2011-ranger/#gsc.tab=0
If you were looking to use your 1997 Explorer it is a less than ideal donor. In addition to the issues outlined concerning PATS differences, there is a missmatch in the fuel system since your truck runs a higher pressure returnless system, and the Explorer uses a lower pressure return style system. Also the AWD 4R70W is not a good match for a 2wd Ranger. If it used a true 4wd transfer case you could just leave out the front shaft, but that will cause problems with the AWD transfer case. A 99-01 Explorer 2wd would be a better choice for your Ranger, but still not great due to the PATS stuff.
I notice you are in California. Before getting too serious about this conversion, you may want to take a good look at their emissions regulations and see if it can even pass inspections. Generally speaking emissions compliance requires a swap using an engine from the same model year or newer and utalizing the engines emissions controls. A 97 drivetrain into a 2004 isn't going to work for that, and they stopped with the 5.0L Explorer in 2001.
Maybe investigate a 4.6L swap from a newer Explorer. It's a harder fit, but probably easier to get passed by the emissions board. It has been done a time or two, but I can't point you to any resources. I think that there is atleast one around the forums (maybe this one?) and I seem to recall that Powernation built one. If you look for the Powernation one it is actually a Mazda, but same basic truck
You didn't ask for this, but... If this truck held sentimental value for me and I wanted to give it a power boost, I'd be looking at swapping in the drivetrain from same year or newer 4.0L SOHC Ranger. Those SOHCs made as much power as the Explorer's 5.0L did in stock form, can be done plug and play if you find the right donor, and will be 100% legal swap easily passing inspections. Then if I wanted more, I'd look into adding forced induction, but you'd have to look into the emissions legality of that for your area. I don't know if Moddbox has CARB certification, but it would probably be easier to get inspected passed than an engine swap with an older model 5.0L engine.
For the record I've been around all of the V6s and the V8. We've had 2 of the 3.0Ls at various times, they weren't bad, but I do understand wanting more. My 99 was the 4.0L OHV before I swapped in a modified 5.0L this past year. My dad has a 2001 4.0L SOHC, it's actually parked at my house since I drove it home from working on my car over there last week. Even now I say that if my Ranger had been the 4.0L SOHC it wouldn't have gotten swapped, I'd probably have installed the MODDBOX supercharger kit and been pretty dang happy. If I ever get lucky with an M90 for a good price, I'll probably scoop it up and see if I can talk dad into it when we eventually have to do timing chains.