<p>What is the best way to include an html entity in XSLT?</p>

<pre><code>&lt;xsl:template match="/a/node"&gt;
    &lt;xsl:value-of select="."/&gt;
    &lt;xsl:text&gt;&amp;nbsp;&lt;/xsl:text&gt;
&lt;/xsl:template&gt;
</code></pre>

<p>this one returns a <strong>XsltParseError</strong></p>

[{'answer_id': 31873, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 8, 'selected': True, 'text': '<p>You can use CDATA section</p>\n\n<pre><code>&lt;xsl:text disable-output-escaping="yes"&gt;&lt;![CDATA[&amp;nbsp;]]&gt;&lt;/xsl:text&gt;\n</code></pre>\n\n<p>or you can describe &amp;nbsp in local DTD:</p>\n\n<pre><code>&lt;!DOCTYPE xsl:stylesheet [ &lt;!ENTITY nbsp "&amp;#160;"&gt; ]&gt;\n</code></pre>\n\n<p>or just use <code>&amp;#160;</code> instead of <code>&amp;nbsp;</code></p>\n'}, {'answer_id': 31878, 'author': 'Tom Lokhorst', 'author_id': 2597, 'author_profile': 'https://Stackoverflow.com/users/2597', 'pm_score': 3, 'selected': False, 'text': '<blockquote>\n  <p>this one returns a <strong>XsltParseError</strong></p>\n</blockquote>\n\n<p>Yes, and the reason for that is that <code>&amp;nbsp;</code> is not a predefined entity in XML or XSLT as it is in HTML.</p>\n\n<p>You could just use the unicode character which <code>&amp;nbsp;</code> stands for: <code>&amp;#160;</code></p>\n'}, {'answer_id': 31886, 'author': 'Pierre Spring', 'author_id': 1532, 'author_profile': 'https://Stackoverflow.com/users/1532', 'pm_score': 4, 'selected': False, 'text': '<p>one other possibility to use html entities from within xslt is the following one:</p>\n\n<pre><code>&lt;xsl:text disable-output-escaping="yes"&gt;&amp;amp;nbsp;&lt;/xsl:text&gt;\n</code></pre>\n'}, {'answer_id': 31894, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 3, 'selected': False, 'text': '<p>XSLT only handles the five basic entities by default: <code>lt</code>, <code>gt</code>, <code>apos</code>, <code>quot</code>, and <code>amp</code>. All others need to be defined as <a href="https://stackoverflow.com/questions/31870/using-a-html-entity-in-xslt-eg-nbsp#31873">@Aku</a> mentions.</p>\n'}, {'answer_id': 32161, 'author': 'James Sulak', 'author_id': 207, 'author_profile': 'https://Stackoverflow.com/users/207', 'pm_score': 3, 'selected': False, 'text': "<p>Now that there's Unicode, it's generally counter-productive to use named character entities.  I would recommend using the Unicode character for a non-breaking space instead of an entity, just for that reason.  Alternatively, you could use the entity <code>&amp;#160</code>;, instead of the named entity.  Using named entities makes your XML dependent on an inline or external DTD.  </p>\n"}, {'answer_id': 6559711, 'author': 'Ayça Deniz', 'author_id': 826401, 'author_profile': 'https://Stackoverflow.com/users/826401', 'pm_score': -1, 'selected': False, 'text': '<p>\n    \n     \n</p>\n\n<p>One space character between text tags should be enough.</p>\n'}, {'answer_id': 7613975, 'author': 'Sergey Ushakov', 'author_id': 972463, 'author_profile': 'https://Stackoverflow.com/users/972463', 'pm_score': 5, 'selected': False, 'text': '<p>It is also possible to extend the approach from 2nd part of <a href="https://stackoverflow.com/questions/31870/using-a-html-entity-in-xslt-e-g-nbsp#31873">aku\'s answer</a> and get all known character references available, like this:</p>\n\n<pre><code>&lt;!DOCTYPE stylesheet [\n  &lt;!ENTITY % w3centities-f PUBLIC "-//W3C//ENTITIES Combined Set//EN//XML"\n      "http://www.w3.org/2003/entities/2007/w3centities-f.ent"&gt;\n  %w3centities-f;\n]&gt;\n...\n&lt;xsl:text&gt;&amp;nbsp;&amp;minus;30&amp;deg;&lt;/xsl:text&gt;\n</code></pre>\n\n<p>There is certain difference in the result as compared to <code>&lt;xsl:text disable-output-escaping="yes"&gt;</code> approach. The latter one is going to produce string literals like <code>&amp;nbsp;</code> for all kinds of output, even for <code>&lt;xsl:output method="text"&gt;</code>, and this may happen to be different from what you might wish... On the contrary, getting entities defined for XSLT template via <code>&lt;!DOCTYPE ... &lt;!ENTITY ...</code> will always produce output consistent with your <code>xsl:output</code> settings.</p>\n\n<p>It may be wise then to use a local entity resolver to keep the XSLT engine from fetching character entity definitions from the Internet. JAXP or explicit Xalan-J users may need a patch for Xalan-J to use the resolver correctly. See my blog <a href="http://s-n-ushakov.blogspot.com/2011/09/xslt-entities-java-xalan.html" rel="nofollow noreferrer">XSLT, entities, Java, Xalan...</a> for patch download and comments.</p>\n'}, {'answer_id': 8910587, 'author': 'Netsi1964', 'author_id': 192080, 'author_profile': 'https://Stackoverflow.com/users/192080', 'pm_score': 0, 'selected': False, 'text': '<p>Thank you for your information. I have written a short blog post based on what worked for me as I was doing XSLT transformation in a template of the <a href="http://www.dynamicweb.com" rel="nofollow">Dynamicweb CMS</a>.</p>\n\n<p>The blog post is here: <a href="http://www.netsi.dk/wordpress/index.php/2012/01/18/how-to-add-entities-to-xslt-templates/" rel="nofollow">How to add entities to XSLT templates</a>.</p>\n\n<p>/Sten Hougaard</p>\n'}, {'answer_id': 8993297, 'author': 'SixOThree', 'author_id': 99774, 'author_profile': 'https://Stackoverflow.com/users/99774', 'pm_score': 1, 'selected': False, 'text': '<p>I found all of these solutions produced a Â character in the blank space.</p>\n\n<p>Using <code>&lt;xsl:text&gt; &lt;/xsl:text&gt;</code> solved the problem for me; but <code>&lt;xsl:text&gt;#x20;&lt;/xsl:text&gt;</code> might work as well.</p>\n'}, {'answer_id': 10751236, 'author': 'Евгений Раткевич', 'author_id': 1309958, 'author_profile': 'https://Stackoverflow.com/users/1309958', 'pm_score': 0, 'selected': False, 'text': '<p>It is necessary to use the entity  <strong>#x160;</strong></p>\n'}, {'answer_id': 14543587, 'author': 'Dave', 'author_id': 463960, 'author_profile': 'https://Stackoverflow.com/users/463960', 'pm_score': 0, 'selected': False, 'text': '<p>I had no luck with the DOCTYPE approach from Aku.  </p>\n\n<p>What worked for me in MSXML transforms on an Windows 2003 server, was</p>\n\n<pre><code>    &lt;xsl:text disable-output-escaping="yes"&gt;&amp;amp;#160;&lt;/xsl:text&gt;\n</code></pre>\n\n<p>Sort of a hybrid of the above.  Thanks Stackoverflow contributors!</p>\n'}]
['https://Stackoverflow.com/questions/31870', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1532/']