Kur*_*aze 3 xml xslt xalan html-entities
我使用 XSL 样式表(使用 Apache Xalan)将 XML 转换为(某种)HTML。在 XML 中可以有像 之类的实体—,必须保持原样。在 XML 文件的开头,我有一个引用这些实体的文档类型。我应该怎么做才能使实体保持不变?
<!DOCTYPE article [
<!ENTITY mdash "—"><!-- em dash -->
]>
Run Code Online (Sandbox Code Playgroud)
在 XML 文本中SAXParseException: Recursive entity expansion, 'mdash'遇到时给我。&mdash
定义和使用实体的方法是:
\n\n<!DOCTYPE xsl:stylesheet [<!ENTITY mdash "—">]>\n<t>Hello — World!</t>\nRun Code Online (Sandbox Code Playgroud)\n\n当使用最简单的 XSLT 样式表进行处理时:
\n\n<xsl:stylesheet version="1.0"\n xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\n <xsl:output method="text"/>\n</xsl:stylesheet>\nRun Code Online (Sandbox Code Playgroud)\n\n产生正确的输出(包含 mdash):
\n\nHello \xe2\x80\x94 World!
重要的:
\n\n在 XSLT 2.0 中,可以使用该<xsl:character-map>指令,以便用实体来表示某些特定的字符。在这个特殊情况下:
<xsl:stylesheet version="2.0"\n xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\n>\n <xsl:output omit-xml-declaration="yes" \n use-character-maps="mdash"/>\n <xsl:character-map name="mdash">\n <xsl:output-character character="—" string="&mdash;" />\n </xsl:character-map>\n\n</xsl:stylesheet>\nRun Code Online (Sandbox Code Playgroud)\n\n当上述转换应用于同一个 XML 文档(如上所示)时,输出为:
\n\nHello — World!\nRun Code Online (Sandbox Code Playgroud)\n