0

I have an XML document containing some escaped HTML string that I want to inject as is in the output document. I have the following doc.xml

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="doc.xsl"?>
<doc>
 <str>&lt;p&gt;foo&lt;/p&gt;</str>
</doc>

and doc.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<xsl:value-of select="doc/str" disable-output-escaping="yes" />
</body>
</html>
</xsl:template>

</xsl:stylesheet>

According to what I have read elsewhere (e.g. here) this should work, but it doesn't, at least when I open the file with Firefox 41: the output reads <p>foo</p>, with no HTML interpretation of the markup.

Community
  • 1
  • 1
P-Gn
  • 23,115
  • 9
  • 87
  • 104

1 Answers1

2

disable-output-escaping is an optional feature of XSLT engines (see the XSLT specification, section 16.4 "Disabling Output Escaping").

Some engines have it, primarily the ones that can output a string ("a serialized representation of the document"). Some don't, primarily the ones that do not output a string.

The engine in Firefox transforms one DOM tree directly into another DOM tree, therefore it's not possible to disable any output escaping, since there is no escaping happening in the first place.

For all practical matters, XSLT is a server-side technology. If you want a reliable feature set, do your transformations on the server.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • disable-output-escaping is equally unreliable server-side: it's generally best avoided, though this is one use-case where it can come in very handy. The other way of handling escaped HTML strings is to parse them into a node tree, which can be done by calling extension functions; details again depend on the processor you are using. – Michael Kay Oct 20 '15 at 09:41
  • @MichaelKay My point was that on the server side one gets to choose the XSLT processor that has the desired features. After that, there is no unreliability. – Tomalak Oct 20 '15 at 09:46