xsl-list
[Top] [All Lists]

RE: Using HTML entity codes within XSL?

2002-12-18 11:18:11
[ Richie B]
      I'm trying to do something like the following in XSL:

<xsl:template match="/">
  <html>
  <body>
      &pound;<xsl:value-of select="data/premiumAmount" />
  </body>
  </html>
</xsl:template>

I'd like to output HTML character entities to a browser, so 
that the browser will render the correct character 
internally, independent of the user's set-up, rather than 
having to use something like a pound symbol "£" for the 
Latin-1 character set - but I obviously get an error if I try 
to use "&pound;" within the XSL ("Reference to undefined 
entity 'pound'.").  The solution at 
http://www.dpawson.co.uk/xsl/characters.html
says to specify 
the character set, but this would defeat the purpose, and 
also systems aren't required to understand any encodings 
other than UTF-8 and UTF-16.  

Actually, character references, like &#160;, are independent of the encoding. 
You can use them and let the processor's serializer take care of handling the 
encoding.  Of course, some code points may not have a representation in a 
particular encoding so the browser could not display them, but that is a 
separate issue (unrelated to XML).

You can also tell the browser what encoding is in use with the right <META> 
element, and most of the main xslt processors will output iso-8859-1 (Latin-1) 
as well as utf-8 and utf-16..

Is there a way I can, in some 
form, use something like "&pound;" or another character 
reference (such as "&eacute;") in my XSL without specifying a 
specific character set/number to use?  Also, I've noticed I 
can already use certain codes such as "&amp;" and "&gt;" - is 
there a list of defined codes which can be used in XSL?


You can declare entities like those in a DTD, but you still have to specify 
them which usually requires using a character reference in the DTD declaration 
of the entity.  You might just as well look up the code for the characters you 
want and use character references directly.  They will generally work in the 
browser.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>