A good scanner will show you the L1-4 lines real-time so you can tell if the readings are getting from transmission to the egs.
When my 3.0i acted like your symptoms was just dirty water in the connector to the transmission.
When you shift does the gear position reliably update on the dashboard? Mine would show nothing some times and other times show impossible gears like 54.
My understanding is the XM is different on the diesel but I'm hoping for your case that the selection switch is external like the v8 and you could take apart and clean the contacts which is what i was about to do on mine when i found the dirty plug.
–awr–
Using Tapatalk VIP on iPhone