Welcome to TRS
When you swap same model engines, but of different Years you need to swap over the upper and lower intakes with fuel injectors, from the old engine to the "new" engine
This is to match fuel systems and wiring
1998, and up, Rangers used 55psi fuel system, 1997 and older use 35psi
Manual or automatic don't matter as far as engine
Vehicle trim, XL or XLT, don't matter
Engine wiring harness and fuel system matter
You will need to get a 1997 upper and lower intake with injectors if the old one is gone
1998 4.0l would only have 1 connection for fuel line
1997 would have 2 connections
Wouldn't be any change in alternators?
So not sure whats up with that
Alternators would have 1(or 2) larger wire connected to B+, stub/nut terminal
Then a 3 wire connector with Yellow wire, White(short jumper) wire and light green wire for the internal voltage regulator
Short White wire plugs in to a single spare terminal on the back of alternator
1998 was first year Ranger had a MEGA Fuse on the outside of the engine fuse box
1997 used a Fusible Link instead
This was for the Alternators B+ wire
So if that's the extra wire that comes out by the fuse box, then you need to get a 12guage Fusible link to hook that wire to the Battery Positive post on starter relay