I had an aftermarket sunroof installed into my 2001 XJ and I love it. I did a lot of research on the subject before doing it because there are a lot of people on both sides of this issue. Basically, what I found out is that in aftermarket sunroofs, you get what you pay for. It you buy one of those cheap pop-up sunroofs, it will leak and creak eventually. If you buy a fully electronic sunroof (which I did) it will come with a drainage system that will "prevent" it from leaking (also a lifetime warranty). It will also probably end up creaking, but such is life with most moving parts. A common misconception with inbuilt sunroofs (tilts and opens between roof and headliner) is that they are designed to leak. Pop-up sunroofs (to my knowledge) are not supposed to leak. They operate on the same principle as weather stripping on a door. And just like door stripping, it wears out and eventually leaks. The difference is that they don't have the drainage system, so that water has nowhere to go but on you.
Now, if you offroad on your jeep, you should avoid a sunroof. Many large, aftermarket sunroofs will require modification/removal of the support beam in the roof that goes over the driver's and passanger's head. Since the XJ is a unibody vehicle, it needs these beams to maintain rigidity. If that beam is removed, you will experience increased body flex and, ultimately, damage or destroy your sunroof.
Can a sunroof be installed on an XJ? Absolutely. As long as the sunroof will physically fit into the roof of the vehicle, it can be installed. However, since the roof has raised rails, this installation should really be done by a professional. I should note that inverted rails (IE Honda Element) should not be attempted.
Its a personal decision and the only advice I will give you is to do what YOU want. Don't let others decide how you make your jeep. Not everyone will think 1000 bucks for a sunroof is worth it, and you can get sunroofs for a couple hundred bucks, but they are not of the same quality. Remember, factory option sunroofs on other vehicles (like the grand cherokee) cost 700-1200 bucks.
BTW, I dont think the newer body XJ (97+) had a sunroof as a factory option. In fact, I dont think Jeep had offered a sunroof option in the XJ since the early 90s. The easiest way to tell a factory from an aftermarket sunroof is to look at the edge of the roof around the glass. If the edge is exposed and it is nicely folded and painted, then it is most likely factory. If the edge is covered by a rubber trim/gasket, it is most likely aftermarket. (however, pop-ups may have the gasket from the factory too).
I am not an expert on this subject, this is just what I found out in my research of the subject. I recommend anyone thinking of doing this to visit
http://sunroofs.org/.