While parsing one of the XML files using XML Serializer in Java, the HTML entities are converted into their corresponding hex code values(like for mdash output is "hexcode value-#x2014;") and hence reflected into the final output file. In order to convert the hex code value to a normal entity, we tried an xsl transformation which throws an error as "javax.xml.transform.TransformerException: use-character-maps attribute is not allowed on the xsl:output element".
Below is the xsl used:-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:output omit-xml-declaration="yes" />
<xsl:character-map name="mdash">
<xsl:output-character character="—" string="&mdash;" />
</xsl:character-map>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@*" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
We used a transformer factory object to transform the final XML to convert hex code into normal entities via xsl file.