不想xslt解释实体字符

问题描述

| 的XML是这样的:
< cell i=\'0\' j=\'0\' vi=\'0\' parity=\'Odd\' subType=\'-1\'> & #34;String& #39;</cell> 
但是在解释了xsl之后,输出是这样的:
< td nowrap=\"true\" class=\"gridCell\" i=\"0\" j=\"0\">\"String\'< /td>
我想保留&#34;和&#39;。我已经尝试过字符映射,但是它不起作用。代码是这样的:
      < xsl:character-map name=\"raquo.ent\">

         <xsl:output-character character=\"\'\" string=\"&amp;apos;\"/>
         <xsl:output-character character=\"&#39;\" string=\"&amp;apos;\"/>
      < /xsl:character-map>

< xsl:output method=\"xml\" version=\"1.0\" encoding=\"UTF-8\" indent=\"yes\" use-character-maps=\"raquo.ent\"/>
有人可以帮忙吗?非常感谢你!     

解决方法

此转换:
<xsl:stylesheet version=\"2.0\"
    xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"
    xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">
    <xsl:output omit-xml-declaration=\"yes\" indent=\"yes\"
    use-character-maps=\"raquo.ent\"/>

    <xsl:character-map name=\"raquo.ent\">
     <xsl:output-character character=\"&#34;\" string=\'&amp;#34;\'/>
     <xsl:output-character character=\"&#39;\" string=\'&amp;#39;\'/>
    </xsl:character-map>

 <xsl:template match=\"node()|@*\">
     <xsl:copy>
       <xsl:apply-templates select=\"node()|@*\"/>
     </xsl:copy>
 </xsl:template>
</xsl:stylesheet>
当应用于提供的XML文档时:
<cell i=\'0\' j=\'0\' vi=\'0\' parity=\'Odd\' subType=\'-1\'>&#34;String&#39;</cell>
产生想要的正确结果:
<cell i=\"0\" j=\"0\" vi=\"0\" parity=\"Odd\" subType=\"-1\">&#34;String&#39;</cell>
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...