我有以下 XML:
<doc>
<chap>
>The bowler >delivers< the ball <
>to the batsman who attempts to <
>hit the ball " with his " bat away from <
>the fielders so he can run to the <
>other end of the pitch and score a run.<
</chap>
</doc>
我必须编写一些 XSL 来对此输入 XML 执行一些任务。但是当我使用复制所有节点时...
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
...在结果文件中,而不是 "
。在生成的文件中,这些内容被转换为 "
。我不希望这种情况发生。
<doc>
<chap>
>The bowler >delivers< the ball <
>to the batsman who attempts to <
>hit the ball " with his " bat away from <
>the fielders so he can run to the <
>other end of the pitch and score a run.<
</chap>
</doc>
是否有任何方法可以将 "
保留在生成的 XML 中?
最佳答案
您可以使用xsl:use-character-maps
,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output use-character-maps="CharMap"/>
<xsl:character-map name="CharMap">
<xsl:output-character character=""" string="&quot;"/>
</xsl:character-map>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
关于xml - 在 XSLT 转换中保留 """实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32323872/