Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 在XSLT转换中保留“”实体_Xml_Xslt - Fatal编程技术网

Xml 在XSLT转换中保留“”实体

Xml 在XSLT转换中保留“”实体,xml,xslt,Xml,Xslt,我有以下XML: <doc> <chap> &gt;The bowler &gt;delivers&lt; the ball &lt; &gt;to the batsman who attempts to &lt; &gt;hit the ball &quot; with his &quot; bat away from &lt;

我有以下XML:

<doc>
    <chap>
        &gt;The bowler &gt;delivers&lt; the ball &lt;
        &gt;to the batsman who attempts to &lt;
        &gt;hit the ball &quot; with his  &quot;  bat away from &lt;
        &gt;the fielders so he can run to the &lt;
        &gt;other end of the pitch and score a run.&lt;
    </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="&quot;" string="&amp;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>
        &gt;The bowler &gt;delivers&lt; the ball &lt;
        &gt;to the batsman who attempts to &lt;
        &gt;hit the ball " with his  "  bat away from &lt;
        &gt;the fielders so he can run to the &lt;
        &gt;other end of the pitch and score a run.&lt;
    </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="&quot;" string="&amp;quot;"/>
    </xsl:character-map>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>