So you said "When these entities occur in my stylesheet, translate them in this way." But that has no effect on the entities that were in the document you wanted to transform.
I suggest you preprocess your document which is not XML using JTidy or Tagsoup and make it into XML. Then
you should have no problem.