Yes you can. Two main issues you'll run into:
1) The '93 A4LD has two solenoids in the valve body: one for the torque converter clutch and one for the 3-4 shift. The '87 A4LD only has one solenoid in the valve body for the TCC. You'll need to account for the electrical difference. From what I understand, you can simply swap the valve body from the '93 A4LD into the '87 A4LD. The only real problem I see with this is if the reason you are replacing trannies is because of a problem in the '93 valve body.
2) You should know that the 4.0 A4LD's were built stronger internally to handle the extra torque of the 4.0. Unless you know that the 2.9 A4LD has been rebuilt to 4.0 specs, you are taking a risk as to how long this used A4LD will last behind your 4.0. At this point, you would need to do a cost/benefit type analysis weighing the cost of installing the used transmission vs. how reliable you need and/or how long you need/want it to last.