XSLT is a language that processes XML at the logical level, not at the lexical level. At the logical level, "'", "'", "#x27;", and "#x0027;" are completely equivalent representations of the same character, and XSLT can't distinguish between them either on input or on output.
If you need to manipulate XML at the lexical level (and I can't see why you should need to) then you need a lower-level tool.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference