Its hard to say, the CPS could fail intermittently, could be fuel supply or MAP sensor, Worn cap/rotor many things really. I had a fuel pump fail in my last 93 ZJ that gave symptoms like this. Had to use a fuel pressure gauge to see that my fuel pressure was not being consistently maintained.
If this is on your 96 XJ, you can start by getting a code reader for OBD2 and see if the problem has thrown any codes. Most likely you would have a check engine light though if it had.
You can also check the cap and rotor for excessive wear and check the distributor shaft for excessive play, I've seen them wear out and make 4.0's run funny.
After that you might have to get down to real troubleshooting which means test for fuel while cranking (might want a fuel pressure gauge) or do like I said in the above post redneck style.
If you have fuel (rail maintains pressure and injectors fire), test for spark.
If you have good spark, test for compression.
Some guys get lucky throwing parts at problems, in my experience you end up spending less time, money and frustration if you methodically follow a logical troubleshooting procedure.