Your number one concern is going to be the spline count. Make sure that the input shaft on the T-case and the output shaft of the tranny are the same count. It would be better if the donor vehicle had the same tranny as your XJ, mainly for driveshaft lentgh matching...
Not sure if in 97 the TJ's had a driver output or a passenger output T-case. I know jeep seemed to enjoy changing stuff up mid-year.
Just my 2 cents...