don't want xslt intepret the entity characters

巧了我就是萌 提交于 2019-12-24 03:28:17

问题


The xml was like this:

< cell i='0' j='0' vi='0' parity='Odd' subType='-1'> & #34;String& #39;</cell> 

But after the intepretion of the xsl, the output is like this:

< td nowrap="true" class="gridCell" i="0" j="0">"String'< /td>

I would like to keep the & #34; and & #39;. I've tried character map,but it doesn't work. The code is like this:

      < 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"/>

Can anyone help? Thank you very much!


回答1:


This transformation:

<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>

when applied on the provided XML document:

<cell i='0' j='0' vi='0' parity='Odd' subType='-1'>&#34;String&#39;</cell>

produces the wanted, correct result:

<cell i="0" j="0" vi="0" parity="Odd" subType="-1">&#34;String&#39;</cell>


来源:https://stackoverflow.com/questions/6109999/dont-want-xslt-intepret-the-entity-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!