RE: [xsl] character entities

Subject: RE: [xsl] character entities
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 28 Apr 2005 20:14:09 +0100
> So, in the example below, I would expect the "&amp;" to output as "&"
> because it is in the source XML file

The &amp; represents an ampersand; it's seen within the XSLT stylesheet as a
single character (for example, string-length() is 1); but if you serialize the
result as XML or HTML then it will be output as &amp; because that's how an
ampersand is represented in XML and HTML.

> and I would expect that
> a character
> reference created in the XSLT template would output as the reference.

You can't create character references in an XSLT template. When you write

<xsl:template match="quote">

the character references are converted by the XML parser into regular
characters. The XSLT processor doesn't know that they were originally written
as character references, any more than it does for the source document.

> I get this mess in place of the quotes:
> (C"b,Ethe <i>O'Hara</i> suitC"b,B)

That's not the output of the stylesheet (or even of the serializer): that's
the output of the software that you're using to display the output of the
serializer on your screen. And it's a mess because you haven't told that
software that you're asking it to display data that's encoded in UTF-8. Either
configure your display software (e.g. text editor) to display UTF-8 correctly,
or generate your output in some other encoding, such as iso-8859-1, that your
display software understands.

Michael Kay

Current Thread