xsl:character-map

Declares a character map defined by a unique name. A stylesheet cannot contain two or more character maps with the same name. Character maps are supported by XSLT 2.0 only.

Format

<xsl:character-map 
  name = qname 
  [use-character-maps = qnames]> 
  [<xsl:output-character> ...] 
</xsl:character-map> 

Description

A character map allows a specific character appearing in a text or attribute node in the final result tree to be substituted by a specified string of characters during serialization. The character map that is supplied as a parameter to the serializer is determined from the xsl:character-map elements referenced from the xsl:output declaration for the selected output definition.

Character/string mappings can be defined in the body of the xsl:character-map element using one or more xsl:output-character elements, or they can be defined in an external character map referenced using the optional use-character-maps attribute. If the character map references multiple external character maps, separate each character map's Qname with a space.

An output definition, after recursive expansion of character maps referenced via its use-character-maps attribute, may contain several mappings for the same character. In this situation, the last character mapping takes precedence.

If a character is mapped, it is not subjected to XML or HTML escaping.

Example

This example shows a composite character map - one constructed using both internally defined character mappings (xsl:output-character), and references to externally defined character maps (the use-character-maps attribute):

<xsl:output name="htmlDoc" use-character-maps="htmlDoc" /> 
  
<xsl:character-map name="htmlDoc" 
  use-character-maps="html-chars doc-entities windows-format" /> 
   
<xsl:character-map name="html-chars" 
  use-character-maps="latin1 ..." /> 
  
<xsl:character-map name="latin1"> 
  <xsl:output-character character="&#160;" string="&amp;nbsp;" /> 
  <xsl:output-character character="&#161;" string="&amp;iexcl;" /> 
  ... 
</xsl:character-map> 
  
<xsl:character-map name="doc-entities"> 
  <xsl:output-character character="&#xE400;" string="&amp;t-and-c;" /> 
  <xsl:output-character character="&#xE401;" string="&amp;chap1;" /> 
  <xsl:output-character character="&#xE402;" string="&amp;chap2;" /> 
  ... 
</xsl:character-map> 
  
<xsl:character-map name="windows-format"> 
  <!-- newlines as CRLF --> 
  <xsl:output-character character="&#xA;" string="&#xD;&#xA;" /> 
  
  <!-- tabs as three spaces --> 
  <xsl:output-character character="&#x9;" string="   " /> 
  
  <!-- images for special characters --> 
  <xsl:output-character character="&#xF001;" 
    string="&lt;img src='special1.gif' /&gt;" /> 
  <xsl:output-character character="&#xF002;" 
    string="&lt;img src='special2.gif' /&gt;" /> 
  ... 
</xsl:character-map> 

XML to PDF

Convert XML to PDF using Stylus Studio's XML publishing tools - the easiest way to design beautiful document layouts for use in XSL:FO based multi-channel publishing and single source publishing applications.

XML-to-XML Mapper

XML to XML mapping tools in Stylus Studio provide a powerful visual interface for mapping XML data from-and-to virtually any data format using industry-standard XSLT and XQuery technologies.

Writing Custom XML Adapters

There are cases where the input format is too complicated for Convert to XML, or both reading and writing of the file format is needed. This section will take you through the process of writing a medium-sized adapter in Java.

An Introduction To XML Schema Development

An Introduction to XML schema development in Stylus Studio covers some of the highlights of our XML Schema Editor, powerful tools for editing, validating, converting and generating XML schema. Watch the video online today!

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member