2

我有一个包含 HTML 代码的 TextBlock 的 XML 文档。

<TextBlock>
  <h1>This is a header.</h1>
  <p>This is a paragraph.</p>
</TextBlock>

然而,在实际的 XML 中,它是这样编码的:

<TextBlock>
  &lt;h1&gt;This is a header.&lt;/h1&gt;
  &lt;p&gt;This is a paragraph.&lt;/p&gt;
</TextBlock>

因此,当我使用<xsl:value-of select="TextBlock"/>它时,它会显示页面上的所有编码。有没有办法使用 XSLT在 TextBlock 元素内进行&lt;转换?<

4

1 回答 1

4
<xsl:value-of select="TextBlock" disable-output-escaping="yes"/>

结果:

<h1>This is a header.</h1>
<p>This is a paragraph.</p>

Firefox 有一个对应的 bug:https ://bugzilla.mozilla.org/show_bug.cgi?id=98168 ,其中包含很多评论,读起来很有趣。

我现在正在寻找解决方法。

编辑

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="disable-output-escaping.xsl"/> 
    <!-- https://bug98168.bugzilla.mozilla.org/attachment.cgi?id=434081 -->
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/TextBlock">
        <xsl:copy>
            <xsl:call-template name="disable-output-escaping"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

通过 Firebug 检查时,结果看起来是正确的:

<textblock>
    <h1>This is a header.</h1>
    <p>This is a paragraph.</p>
</textblock>
于 2010-12-20T17:52:35.970 回答