Using HTML entities in XSL
From VYRE
There are occasions when you need to output special characters, such as a £ sign as HTML entities. One simple method is to wrap the entity inside an xsl:text tag like the following:
<xsl:text disable-output-escaping="yes">&pound;: </xsl:text><xsl:value-of select="price"/></xsl:text>
This however can be labourious, having to repeat this method everytime you want to output an entity. An alternative method is to declare any entities you desire in a DOCTYPE in your stylesheet. You can do so in the following way:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY pound "£"> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="UTF-8"/> <xsl:template match="/"> </xsl:template> </xsl:stylesheet>
Once an entity is declared in a DOCTYPE then it can used anywhere in your output:
£: <xsl:value-of select="price"/>
It can be useful to declare a set of common HTML entities in your stylesheet:
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> <!ENTITY copy "©"> <!ENTITY reg "®"> <!ENTITY trade "™"> <!ENTITY mdash "—"> <!ENTITY ldquo "“"> <!ENTITY rdquo "”"> <!ENTITY pound "£"> <!ENTITY euro "€"> ]>
Take a look at the W3Schools website for more information on HTML entities.
