Is your X terra a running drivable truck? If so i hope the trade is not straight across. With "bad transmission" these should be in the $1000 range, give or take.
That being said...if you are happy then just move forward and let the fun begin!. If it is the burgundy truck pictured above, nice looking truck! As for bad trans already great info here. A few people have thought they had bad trans and found it to be other stuff. So try to diagnose what is really going on.
If you end up replacing the trans i think some one fond a good used one in the $600 range not to long ago. Not too bad. If this is just a better type truck then i think you can just swap transmissions. If this will be yours for a long time then i agree 100% on pull the motor and trans all together. But if you do it right with a crap load of PM using OEM parts it will triple your budget. Just be ready for that. I am not as familiar with the older motor. But i would count on replacing EVERYING made of rubber. entire coolant system,pump, and radiator, all power steering hoses, gaskets including anything like rear main and front main, oil pump valve cover, distributer, throttle body and oil pan, and so on, motor mounts, You might as well rebuild power steering pump, alt and starter while it is all apart. also replace any of the dried electrical connections with new OEM plugs. Plus all the normal PM such as plugs wires filters.
I dont know as much about the older motor. On the newer motor i would do aq HG while it was out which is why i said 3X your budget. I know the older does not need that. But not sure if it has its own issues. On the newer you would want to do front oil pump and rear main/arch as well just because they are trick when installed to change. I dont know if your older motor has the same things. But you get the idea.
If you are going to keep this a long time, trust me, this is how you will want to go. You will end up dropping a few 1000 now but you will end up with a truck that doesn't drip a drop or burn any oil, runs perfect temps all day long. And you will know the motor well.