xsltxml-parsingsaxonsaxparserxslt-3.0

Unescape some entities during xsl transformation


We have done an xsl transformation to convert hexcode values into entities. Now after transformation, there are some entites which are converting into their corresponding values like & gets converted into '&', similar is the case for §. For keeping the entities unchanged, we have used the below xsl code:-

<xsl:stylesheet version='3.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
<xsl:output method="xml" omit-xml-declaration="no" use-character-maps="mdash" />
<xsl:character-map name="mdash">
<xsl:output-character character="&#x2014;" string="&amp;mdash;"/>
<xsl:output-character character="&amp;" string="&amp;amp;" />
<xsl:output-character character="&quot;" string="&amp;quot;" />
<xsl:output-character character="&apos;" string="&amp;apos;" />
<xsl:output-character character="&sect;" string="&amp;sect;" />
</xsl:character-map>
<!--=================================================================-->
<xsl:template match="@* | node()">
<!--=================================================================-->
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Now transformation happens fine for most of the entities, but for &sect, the below error is displayed:-

SXXP0003: Error reported by XML parser: The entity "sect" was referenced, but not declared.

Is there a way to unescape this entity sect?


Solution

  • Use a numeric character reference e.g. &#167;:

    <xsl:output-character character="&#167;" string="&amp;sect;" />