Search code examples
xslt

Using an HTML entity in XSLT (e.g.  )


What is the best way to include an html entity in XSLT?

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

this one returns a XsltParseError


Solution

  • You can use CDATA section

    <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
    

    or you can describe &nbsp in local DTD:

    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#160;"> ]>
    

    or just use &#160; instead of &nbsp;