Typical setup for wiring is constant power with two switched grounds. The pink wire will provide battery constant power (so the lights will work when a door is opened), the yellow wire provides switched ground from the forward cabin (activated with doors and the dash light switch), and a purple wire w/ yellow stripe provides switched ground from the latch mechanism in the hatch (only activates cargo lamp). Usually there is a button on the lamp to interrupt the purple w/ yellow wire so that you can turn it off when needed
Almost all of the XJs came with a switch on the lamp. However almost all of them have a broken switch, because the plastic tends to melt when the lamp is left on for extended periods. Some people have wired small toggle switch from radio shack into the side of the lamp housing to provide the interrupt. Another option is to find the wire in the D-pillar and put a small little switch there. The switch doesn't have to be fancy, just something to open and close the ground leg
You can go really crazy with this if you want. I have a dual-housing RV lamp with a three-position switch that also controls secondary work lights in the hatch, and a magnetic safety cut-off switch in the D-pillar and hatch panel to kill the hatch lights when the hatch is closed.