I have XML that has encoded HTML data. I am trying to render the data but can't seem to figure out how. Best I can tell is I need to disable-output-escaping="yes"
twice but not sure how to do that.
For example, this is a snippet of my XML:
<root>
<node value="&lt;b&gt;body&lt;/b&gt;" />
</root>
My XSLT is outputting HTML. Here is the rendered output (the HTML source) with various options
<xsl:value-of select="@value" />
outputs&lt;b&gt;hi&lt;/b&gt;
<xsl:value-of select="@value" disable-output-escaping="yes" />
outputs<b>hi</b>
I would like it to output <b>hi</b>
to the HTML source so its actually rendered as a bolded hi. Does that make sense? Is that possible?
Assuming Sharepoint as a Microsoft .NET product uses XslCompiledTransform you could try to implement the unescaping and parsing with extension "script" (C# or VB or JScript.NET code embedded in XSLT) as follows:
If you have access to an XSLT processor (like any version of Saxon 9.7 or Exselt or the latest Altova or XmlPrime) supporting the XPath 3 functions
parse-xml
andparse-xml-fragment
you can write that template without extension functions (in aversion="3.0"
stylesheet) asEscaping is the process of turning
<
into<
. If you disable escaping, it will leave<
as<
. What you want to achieve is to turn<
into<
, which would normally be called "unescaping".In the normal course of events, a parser performs unescaping, while a serializer performs escaping. So if you want to unescape characters, you need to put them through a parsing process, which means you need to take the content of the
@value
attribute and put it through an operation like fn:parse-xml-fragment() in XPath 3.0, or an equivalent extension function in your chosen processor.Output your result with
disable-output-escaping
, then treat it again in another XSL withdisable-output-escaping
.