Parsing an XML String Using XSLT

I have an XML document with a TextBlock that contains HTML code.

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

In real XML, however, it is encoded as follows:

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

Therefore, when I use <xsl:value-of select="TextBlock"/> , it displays all the encodings on the page. Is there a way to use XSLT to convert &lt; in < inside a TextBlock element?

+2
xslt decoding
source share
1 answer
 <xsl:value-of select="TextBlock" disable-output-escaping="yes"/> 

and the result:

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

Firefox has a corresponding error: https://bugzilla.mozilla.org/show_bug.cgi?id=98168 , which contains a lot of comments and interesting reading.

Now I am looking for a fix.

EDIT

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

When checking through Firebug, the result looks correct:

 <textblock> <h1>This is a header.</h1> <p>This is a paragraph.</p> </textblock> 
+4
source share

Source: https://habr.com/ru/post/650682/


All Articles