Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT string with HTML entities - How can I get it to render as HTML?

Tags:

html

string

xslt

I'm completely new to using XSL, so if there's any information that I'm neglecting to include, just let me know.

I have a string in my XSLT file that I can display like this:

<xsl:value-of select="@Description/>

and it shows up, rendered in a browser like:

<div>I can't do anything about the html entities existing in the text.</div> <div>This includes quotes, like  &quot;Hello World&quot; and sometimes whitespaces.&nbsp;</div>

What can I do to get this string rendered as html, so that <div></div> results in newlines, &quot; gives me ", and &nbsp; gives me a space?

I could elaborate on things I've already tried that haven't worked, but I don't know if that's relevant.

like image 672
Kache Avatar asked May 18 '10 00:05

Kache


2 Answers

I think you want to set the following attribute as so:

<xsl:value-of select="@Description" disable-output-escaping="yes"/>
like image 95
Ben.Vineyard Avatar answered Nov 04 '22 14:11

Ben.Vineyard


Why do you need to have entities output? To the browser &nbsp; is the same as &#xA0; -- in both cases it will display a non-breaking space.

There is a feature in XSLT 2.0 called character-maps, that provide this functionality, if really needed. It is an XSLT best practice to try not to use DOE, unless absolutely necessary.

Also, DOE is not a mandatory feature of XSLT and some XSLT processors may not implement it. This means that an XSLT application that uses DOE is generally not portable across different XSLT processors.

like image 25
Dimitre Novatchev Avatar answered Nov 04 '22 15:11

Dimitre Novatchev