xsltxml-parsingsaxonsaxparserxslt-3.0

character attribute must be a single XML character error while unescaping some entities


There are some user defined entites in the xml data. In order to unescape those entities, we are using entity reference in the DOCTYPE mentioned in the below code:-

<!DOCTYPE xsl:stylesheet [
<!ENTITY sect "&amp;sect;">
]>
<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>

while execution, we face the below error:-

  Error at xsl:output-character on line 11 column 64
  XTSE0020: character attribute must be a single XML character

This error is for sect entity on line 11.


Solution

  • In the DTD, instead of !ENTITY sect "&amp;sect;" use !ENTITY sect "&#167;".