Re: [xsl] special characters

Subject: Re: [xsl] special characters
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 23 May 2003 11:38:53 +0100

> how can you make special characters(like &eacute;) appairs in a text
> output file in xsl encoding?

I thought I'd take this opportunity to describe one of the new
features in XSLT 2.0 -- the ability to map characters in text nodes
and attribute values during output onto arbitrary strings. This is
done through a "character map".

To say that é should be output as &eacute;, for example, you can
create a character map as follows:

<xsl:character-map name="latin-1">
  <xsl:output-character character="&#xE9;" string="&amp;eacute;" />

and reference this character map from your output definition:

<xsl:output use-character-maps="latin-1" />

When the result tree is output, every occurrence of é, in text or in
attribute values, will be replaced by the string &eacute;.

Note that this will work for é characters that get into the output
from being part of the source document as well as the é characters
that you use in your stylesheet. It also does the replacement in
attribute values as well as text nodes. In both ways it's more
powerful than d-o-e.

Of course that might mean that your output is not well-formed, because
there's no guarantee that the output has an entity declaration for the
&eacute; entity, so you should usually specify a doctype-system so
that the output includes a DOCTYPE declaration that contains the
relevant entity declaration.



Jeni Tennison

 XSL-List info and archive:

Current Thread