That cap is a check valve, and the hose is an air breather. When the oil heats up, the air overtop of it expands and needs to be vented so you don't pop the gasket (it can happen,) and the valve on the end is to help prevent water ingestion as well if you "swim" your XJ. The wiggly part is the actual valve proper.
For your other question, the transmission breather hose (same basic function) is found, IIRC, bolted with one of the two bolts at the driver's rear of the engine, same place where you find the engine grounds (near and aft of the distributor.) I don't recall the proper orientation of the pipe end, but pointing it more or less downward wants to sound correct (so it won't accidentally catch anything, and anything that might get spit out goes down and away from the windscreen.) HTH
5-90