xsl:character-map

  1. character-map_1-input.xml

  2. <?xml version="1.0"?>
  3. <test>&#169; 1850 by Søren Kierkegaard</test>
  1. character-map_1-stylesheet.xsl

  2. <?xml version="1.0"?>
  3. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.   <xsl:character-map name="a">
  5.     <xsl:output-character character="ø" string="o"/>
  6.     <xsl:output-character character="&#169;" string="Copyright &#169;"/>
  7.   </xsl:character-map>
  8.   <xsl:output indent="yes" use-character-maps="a"/>
  9.   <xsl:template match="/">
  10.     <xsl:value-of select="test"/>
  11.   </xsl:template>
  12. </xsl:stylesheet>
  1. character-map_1-output.xml

  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <test>Copyright © 1850 by Soren Kierkegaard</test>

Comment

xsl:output-character used inside xsl:character-map can only take one character and replace it with something else in output. It can also be used instead of the "disable-output-escaping" attribute in xsl:value-of and xsl:text. "DOE" is deprecated in XSLT 2.0.

The spec has many good examples: http://www.w3.org/TR/xslt20/#element-character-map.

Updated 2009-03-19