Reputation: 21
There have some userdefined entities in the input xml like &key;
and ‐
.
We have defined these entites as DOCTYPE in the below xsl:-
<!DOCTYPE xsl:stylesheet [
<!ENTITY key "&key;">
<!ENTITY hyphen "&hyphen;">
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
exclude-result-prefixes="#all"
expand-text="yes"
version="3.0">
<xsl:output method="xml" omit-xml-declaration="no" use-character-maps="mdash" />
<xsl:character-map name="mdash">
<xsl:output-character character="—" string="&mdash;"/>
<xsl:output-character character="&" string="&amp;" />
<xsl:output-character character=""" string="&quot;" />
<xsl:output-character character="'" string="&apos;" />
<xsl:output-character character="§" string="&sect;" />
<xsl:output-character character="&key;" string="&key;" />
<xsl:output-character character="‐" string="&hyphen;" />
</xsl:character-map>
<xsl:mode on-no-match="shallow-copy"/>
</xsl:stylesheet>
Now in output as well, the entites should remain same, i.e. &key;
and ‐
.
But while using the userdefined entites defined under DOCTYPE in output character, the below error occurs:-
Static error at xsl:output-character
XTSE0020: character attribute must be a single XML character
Is there a way to use it or unescape the entities in output xml for &key;
and ‐
?
Upvotes: 0
Views: 47
Reputation: 163587
Is there a way to use it or unescape the entities in output xml for &key; and ‐?
Character maps provide a way to change the serialization of individual characters in the XSLT output. They don't provide a way to change the serialization of arbitrary strings. So the simple answer is "no".
If you really want to generate entity references in your serialized output, my recommendation would be that the XSLT processor should generate something like §key;
and you should convert this to &key;
in a post-processing phase (using non-XML-aware tools).
However, I would also consider whether using entity references is the best way to meet your business requirements. Using XInclude elements or processing instructions can give you more flexibility.
Upvotes: 0