使用XSLT解析XML字符串

前端之家收集整理的这篇文章主要介绍了使用XSLT解析XML字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 XML文档,其中包含一个包含HTML代码的TextBlock. @H_403_1@<TextBlock> <h1>This is a header.</h1> <p>This is a paragraph.</p> </TextBlock>

但是,在实际的XML中,它的编码如下:

@H_403_1@<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转换& lt;到<在TextBlock元素中?

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

结果:

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

Firefox有一个相应的错误https://bugzilla.mozilla.org/show_bug.cgi?id=98168,其中包含很多评论,是一个有趣的阅读.

我现在正在寻找解决方案.

编辑

@H_403_1@<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进行检查时,结果看起来是正确的:

@H_403_1@<textblock> <h1>This is a header.</h1> <p>This is a paragraph.</p> </textblock>

猜你在找的XML相关文章