XML technologies / XSLT / Reference: XSLT 1.0 and 2.0 elements / output-character

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 6.)

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

 

Sub-instruction xsl:output-character assigns an alias replacement string for serialization in the result document to special characters represented by character entities.

Classification

Sub-instruction

Function group

Character-map output format definition

Introduced

XSLT 2.0

Position in the stylesheet and permitted contents:

Element xsl:output-character is subordinate to declaration xsl:character-map and is its only permitted child element. It is always empty.

Attributes:

Standard attributes apply. There are also two required attributes, character and string.

character

Value

char

Usage

required

Introduced

XSLT 2.0

The attribute value is a character entity in hexadecimal form � or decimal form �. Every occurrence is replaced by the string in attribute string.

Note: No replacement occurs if an entity occurs in an element or region where escaping is disabled.

string

Value

ersetzungsstring

Usage

required

Introduced

XSLT 2.0

The attribute value is a string xs:string used in the result document instead of the character named by attribute character.

Usage:

Sub-instruction xsl:output-chacter defines the string inserted in the result instead of a character entity specified here. This replacement definition is called “character mapping”.

The sub-instruction occurs inside named declarations xsl:character-map. Several declarations can be combined through their attributes use-character-maps into a modular character mapping declaration.

Attribute use-character-maps can name the QNames of further declarations xsl:character-maps whose instructions xsl:output-character are included. External declarations are included in listed order, after instructions already present in the enclosing declaration.

This matters because the last instruction xsl:out­put-character in document order wins in a duplicate. An instruction included from another declaration xsl:character-map therefore always overrides one in the including declaration.

No character mapping when output escaping is disabled:
A character entity or special character in a region where output escaping is disabled, for example with attribute disable-output-escaping="yes", is not replaced by character mapping.

No automatic escaping for mapped characters:
A special character or entity named in a character map is excluded from normal escaping for output format "html" or "xhtml" because character mapping takes precedence over automatic escaping.

Example – Use within xsl:character-map:

<xsl:output name="html-dokument" use-character-maps="html-entities"/>
<xsl:character-map name="html-entities">
  <!-- geschuetztes Leerzeichen -->
  <xsl:output-character character="&#160;" string="&amp;nbsp;"/>
  <!-- grosses A, Umlaut -->
  <xsl:output-character character="&#196;" string="&amp;Auml;"/>
  <!-- kleines a, Umlaut -->
  <xsl:output-character character="&#228;" string="&amp;auml;"/>
  <!-- (und so weiter...) -->
  ...
</xsl:character-map>

Here, a declaration xsl:output refers, through its attribute use-character-maps, to a named declaration xsl:character-map.

Within it, instructions xsl:output-character replace special characters during serialization with exact strings, here predefined HTML entities.

For output formats "html" or "xhtml", this deliberately overrides automatic escaping, because definitions using xsl:character-map take precedence over automatic character replacement.

Element definition:

XSLT 1.0:

Element unavailable in XSLT 1.0.

XSLT 2.0:

<!-- Category: sub-instruction -->
<xsl:output-character
     character = char
     string = string 
/>

   

  

back to top