使用XSLT解析XML字符串 [英] Parsing XML string using XSLT
问题描述
我有一个XML文档,其中的TextBlock包含HTML代码。
I have an XML document that has a TextBlock that contains HTML code.
<TextBlock>
<h1>This is a header.</h1>
<p>This is a paragraph.</p>
</TextBlock>
但是在实际的XML中,其编码如下:
In the actual XML, however, it is coded like this:
<TextBlock>
<h1>This is a header.</h1>
<p>This is a paragraph.</p>
</TextBlock>
所以当我使用< xsl:value-of select = TextBlock />
会在页面上显示所有编码。是否可以使用XSLT在TextBlock元素内将& lt;
转换为<
?
So when I use <xsl:value-of select="TextBlock"/>
it displays all of the coding on the page. Is there a way using XSLT to convert <
to <
within the TextBlock element?
推荐答案
<xsl:value-of select="TextBlock" disable-output-escaping="yes"/>
,结果为:
<h1>This is a header.</h1>
<p>This is a paragraph.</p>
Firefox有一个相应的错误: https://bugzilla.mozilla.org/show_bug.cgi?id=98168 ,其中包含很多评论,是一本有趣的文章。
Firefox has a corresponding bug: https://bugzilla.mozilla.org/show_bug.cgi?id=98168, which contains a lot of comments and is an interesting reading.
我正在寻找修复程序。
编辑
<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检查时,结果看起来正确:
When inspecting via Firebug, the result looks correct:
<textblock>
<h1>This is a header.</h1>
<p>This is a paragraph.</p>
</textblock>
这篇关于使用XSLT解析XML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!