1
0
mirror of https://github.com/alexandrev/xslt-lab.git synced 2026-09-18 19:43:16 +00:00
Files
xslt-lab/site/content/xslt/functions/xsl-output-character.md
T
alexandrev-tibco 53e90ef86e feat(blog): complete XSLT/XPath reference — 229 function pages
Full coverage of XSLT 1.0, 2.0 and 3.0 elements and XPath functions:
- 59 XSLT elements (xsl:stylesheet → xsl:use-accumulators)
- 170 XPath functions (1.0 node/string/numeric/boolean, 2.0 sequence/
  date/QName/string, 3.0 HOF/map/array/JSON/streaming)
Each page: description, parameters table, return value, 2 runnable
Saxon examples with input XML + stylesheet + output, notes, cross-links.
xsltCompletions.js: all 229 entries now have blogSlug for hover links.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 09:28:05 +02:00

3.8 KiB

title, description, date, version, versionLabel, category, syntax, tags
title description date version versionLabel category syntax tags
xsl:output-character Specifies a single character-to-string substitution within an xsl:character-map, applied by the serializer when writing output. 2026-04-18T00:00:00Z 2.0 XSLT 2.0 element <xsl:output-character character="&" string="&amp;"/>
xslt
reference
xslt2

Description

xsl:output-character is a child element of xsl:character-map. It maps a single Unicode character to a replacement string that the serializer writes literally in the output — bypassing normal XML escaping. Each xsl:output-character handles exactly one character.

The character attribute must be a single XML character (specified as a literal character or a character reference such as &#160;). The string attribute is the text string written to the output in its place — including any markup or entity references you want to appear literally.

Parameters

Parameter Type Required Description
character Single XML character Yes The Unicode character to intercept during serialization.
string xs:string Yes The string to write in place of the character.

Return value

No output. This declaration is used only by the serializer when the enclosing xsl:character-map is active.

Examples

Common HTML entity mappings

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:character-map name="html5-entities">
    <xsl:output-character character="&#160;"  string="&amp;nbsp;"/>
    <xsl:output-character character="&#169;"  string="&amp;copy;"/>
    <xsl:output-character character="&#174;"  string="&amp;reg;"/>
    <xsl:output-character character="&#8226;" string="&amp;bull;"/>
    <xsl:output-character character="&#8212;" string="&amp;mdash;"/>
    <xsl:output-character character="&#8211;" string="&amp;ndash;"/>
  </xsl:character-map>

  <xsl:output method="html" use-character-maps="html5-entities"/>

  <xsl:template match="/content">
    <p><xsl:value-of select="."/></p>
  </xsl:template>
</xsl:stylesheet>

If the input contains © (U+00A9) and (U+2014), the output will contain &copy; and &mdash; literally.

Escaping special characters for legacy systems

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <!-- Replace curly quotes with straight quotes for legacy system compatibility -->
  <xsl:character-map name="straighten-quotes">
    <xsl:output-character character="&#8216;" string="'"/>
    <xsl:output-character character="&#8217;" string="'"/>
    <xsl:output-character character="&#8220;" string='"'/>
    <xsl:output-character character="&#8221;" string='"'/>
  </xsl:character-map>

  <xsl:output method="text" use-character-maps="straighten-quotes"/>

  <xsl:template match="/">
    <xsl:value-of select="/text"/>
  </xsl:template>
</xsl:stylesheet>

Input text: He said &#8220;hello&#8221; and she replied &#8216;hi&#8217;. Output text: He said "hello" and she replied 'hi'.

Notes

  • The character attribute must contain exactly one XML character. Strings are not supported; use one xsl:output-character per character.
  • The string attribute value is written verbatim. If it contains characters that would normally be escaped by the serializer, the character map takes precedence.
  • A character can appear in only one xsl:output-character within the combined set of active character maps.
  • This element has no effect on the internal XDM tree; it only affects the serialized text output.

See also