With xsl:character-map a uniform substitution of specified characters by a string can be achieved. xsl:character-map must be a child of xsl:stylesheet and it contains one or more xsl:output-characters. The character specifies the original character which is replaced by the value of attribute string.
Element xsl:result-document can have an attribute use-character-maps which specifies one or several named character maps to be used for the required substitution.
In the example the standard output does not use any character map while output to file "aaa.xml" substitutes some characters.
|
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:param name="outdir">/path/to/outdir</xsl:param> <xsl:character-map name="cmap"> <xsl:output-character character="@" string=" at "/> <xsl:output-character character="ࢮ" string="?!"/> </xsl:character-map> <xsl:template match="/aaa"> <xsl:copy-of select="*"/> <xsl:result-document href="{$outdir}/aaa.xml" use-character-maps="cmap"> <xsl:copy-of select="*"/> </xsl:result-document> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa> <bbb>joe@zvon</bbb> <ccc>AࢮB</ccc> </aaa> |
Output
<bbb>joe@zvon</bbb> <ccc>AࢮB</ccc> aaa.html
<body> <h1>Title</h1> <hr> <p>text</p> </body> aaa.xhtml
<body> <h1>Title</h1> <hr></hr> <p>text</p> </body> aaa.txt
Title
text
aaa.xml
<body> <h1>Title</h1> <hr/> <p>text</p> </body> |
| Previous chapter: | Multiple stylesheets |
| Next chapter: | Context |
| Previous page: | Output in different formats: xml, html, xhtml, and text |
| Next page: | - - - |