That's a strange requirement.
Since XSLT works on a parsed document model, you cannot do this reliably. In particular, the distinction between equivalent notations will necessarily be lost. Equivalent notations include things like <tag></tag>
versus <tag/>
, or é
versus é
.
That said, a general approach that might work would be using the mode
attribute of xsl:template
and xsl:apply-template
to switch to a mode that explicitly render all elements as text. In effect you would be writing a XML serializer in XSLT.
One issue though is that you would have to double-escape special characters such as <>"'
when present in attribute values and text nodes. And XSLT is quite inefficient at this sort of string munging.
Another issue would be rendering namespace prefixes reasonably. You can almost certainly do it, but that be quite horrible.