[2.0] <xsl:character-map>

Defines a set of characters, each of which should be replaced by a string of characters. This allows you to put nonstandard characters in the values of elements and attributes. An <xsl:character-map> works much like an XML <!ENTITY> declaration. Use a <xsl:character-map> in place of the disable-output-escaping attributes of <xsl:text> and <xsl:value-of> defined in XSLT 1.0. (Using the disable-output-escaping attribute is deprecated in XSLT 2.0.)



Required Attribute


The name of this character map.

Optional Attribute


The space-separated names of any character maps included in this character map. As you would expect, it is a fatal error if a character map includes itself, directly or indirectly. It is also a fatal error if a character map attempts to include a character map that does not exist.


Zero or more <xsl:output-character> elements.

Appears in

<xsl:character-map> appears as a child of the <xsl:stylesheet> element.

Defined in

XSLT section 20, “Serialization.”


We’ll define a simple example that has a couple of useful functions. First of all, we’ll create a character mapping that replaces tab characters (&#x9;) with two spaces; tab characters are often displayed as eight characters wide, which can cause problems when displaying indented code listings. We’ll also create a couple of graphics that should be displayed in place of certain characters. Here’s the XML source we’ll use:

<?xml version="1.0" encoding="utf-8"?> ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.