Xml 在XSLT转换中保留“”实体
我有以下XML:Xml 在XSLT转换中保留“”实体,xml,xslt,Xml,Xslt,我有以下XML: <doc> <chap> >The bowler >delivers< the ball < >to the batsman who attempts to < >hit the ball " with his " bat away from <
<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>
我们可以看到您的XSLT吗?从XML的角度看,它们都是相同的,它们只是编写相同内容的另一种方式,例如,在属性中有时很方便。这将起作用,+1,但是如果输入还包含未转义的引号,并且不应该再次转义,这也将转义这些引号。
<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 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>