[ACCEPTED]-Using an HTML entity in XSLT (e.g. )-xslt
You can use CDATA section
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
or you can describe 2   in local DTD:
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
or just use  
instead 1 of
It is also possible to extend the approach 16 from 2nd part of aku's answer and get all known character 15 references available, like this:
<!DOCTYPE stylesheet [
<!ENTITY % w3centities-f PUBLIC "-//W3C//ENTITIES Combined Set//EN//XML"
"http://www.w3.org/2003/entities/2007/w3centities-f.ent">
%w3centities-f;
]>
...
<xsl:text> −30°</xsl:text>
There is 14 certain difference in the result as compared 13 to <xsl:text disable-output-escaping="yes">
approach. The latter one is going to 12 produce string literals like
for all kinds 11 of output, even for <xsl:output method="text">
, and this may happen 10 to be different from what you might wish... On 9 the contrary, getting entities defined for 8 XSLT template via <!DOCTYPE ... <!ENTITY ...
will always produce output 7 consistent with your xsl:output
settings.
It may be 6 wise then to use a local entity resolver 5 to keep the XSLT engine from fetching character 4 entity definitions from the Internet. JAXP 3 or explicit Xalan-J users may need a patch 2 for Xalan-J to use the resolver correctly. See 1 my blog XSLT, entities, Java, Xalan... for patch download and comments.
one other possibility to use html entities 1 from within xslt is the following one:
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
this one returns a XsltParseError
Yes, and the reason for 4 that is that
is not a predefined entity 3 in XML or XSLT as it is in HTML.
You could 2 just use the unicode character which
stands 1 for:  
XSLT only handles the five basic entities 2 by default: lt
, gt
, apos
, quot
, and amp
. All others need 1 to be defined as @Aku mentions.
Now that there's Unicode, it's generally 7 counter-productive to use named character 6 entities. I would recommend using the Unicode 5 character for a non-breaking space instead 4 of an entity, just for that reason. Alternatively, you 3 could use the entity  
;, instead of the named 2 entity. Using named entities makes your 1 XML dependent on an inline or external DTD.
I found all of these solutions produced 2 a  character in the blank space.
Using <xsl:text> </xsl:text>
solved 1 the problem for me; but <xsl:text>#x20;</xsl:text>
might work as well.
Thank you for your information. I have written 4 a short blog post based on what worked for 3 me as I was doing XSLT transformation in 2 a template of the Dynamicweb CMS.
The blog post is here: How to add entities to XSLT templates.
/Sten 1 Hougaard
It is necessary to use the entity #x160;
0
I had no luck with the DOCTYPE approach 4 from Aku.
What worked for me in MSXML transforms 3 on an Windows 2003 server, was
<xsl:text disable-output-escaping="yes">&#160;</xsl:text>
Sort of a 2 hybrid of the above. Thanks Stackoverflow 1 contributors!
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.