I had an issue where the rear dome light would turn on with all the doors except for the rear hatch. I did notice there was a button on the rear dome light but it didn't do anything. I took the light apart and found the switch melted; turns out that is another little issue XJs have.
After I fixed the switch by installing a new rocker switch in place of the burnt up one, I figured all was good 'cause the switch now turned the lights on/off when the hatch was open.
A few weeks later, we were out foolin' around in the dez, and all of a sudden the dome lights came on by themselves then went off, then came on and stayed on. I flipped the switch I had installed and the lights went out. Hmmm sumpin aint right. The following weekend I decided to try and locate a door switch for the hatch. The wiring diagram shows one, but doesn't state WHERE it is. I was figuring it likely a mercury tilt switch, but it ends up that the switch is in the gate where the latch is. If I stuffed my finger up in the hole, I could make the dome light flicker.
WTH, got nuthin' better to do, so I started taking things apart. Turns out it's pretty simple to fix and after fixing it and visiting the local junk...err, auto recycling yards and looking at the multitude of XJs there, this seems to be a very common problem. After the fix, your dome lights will come on with the hatch opening and you will be able to leave the hatch open and turn the lights off.
Torx driver, vice, needle nose pliers, punch, drill and 3/16 bit, small ballpeen, small wire brush, piece of emery cloth, rivet gun with a short 3/16 rivet, your favorite adult beverage.
First thing to do is to make sure the switch works on the rear dome light. If it does, continue on, if not fix that first. Use a DVOM to check the switch operation. Resistance readings across the switch contacts should show an open circuit (OL), or a closed circuit (.002 ohms or so), based on position of switch.
After that, remove the panel on the hatch. I won't go into detail on that.
Disconnect the latch rod and use the torx driver to remove the cover plate and latch. You'll need to unplug the wires as you remove the latch as there's not enough room for one of them to be removed with the latch in place.