How can I save entity references when converting XML using XSLT (2.0)? With all the processors I tried, the entity gets the default permission. I can use xsl:character-map
to handle character objects, but what about text objects?
For example, this XML:
<!DOCTYPE doc [ <!ENTITY so "stackoverflow"> <!ENTITY question "How can I preserve the entity reference when transforming with XSLT??"> ]> <doc> <text>Hello &so;!</text> <text>&question;</text> </doc>
Converts with the following XSLT:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
outputs the following result:
<doc> <text>Hello stackoverflow!</text> <text>How can I preserve the entity reference when transforming with XSLT??</text> </doc>
The result should look like an input (minus the doctype declaration):
<doc> <text>Hello &so;!</text> <text>&question;</text> </doc>
I hope I donβt need to pre-process the input, replacing all ampersands with &
(e.g. &question;
), and then process the output, replacing all &
on &
.
Maybe this is a specific processor? I am using Saxon 9.
Thanks!
Daniel Haley
source share