I wish to generate a generic code for parsing special characters in xslt. I wish to replace all special characters found in any node of the xml document with symbols of my choice.
eg special characters= "®"; also" ©"; etc
I have tried something like follows but nothing happens.
<xsl:template match="*">
<xsl:choose>
<xsl:when test="contains(.,'&ndash;')">
<xsl:value-of select="replace(.,'&ndash;','-')" />
</xsl:when>
</xsl:choose>
</xsl:template>
the function of character output is:
<xsl:output-character character=" " string="&nbsp;" />
I wish to do the opposite i.e replace string with character(replace &nbsp;
with  
)
If XSLT 2.0 is at your disposal, use character maps for this. You can find the relevant piece of the specification here.
Define the usage of a character map as a top-level element of your stylesheet:
Then, determine which characters you'd like to replace with a string of your choice during serialization. A character map consists of
output-character
elements where the@character
attribute means the character you wish to replace and@string
its replacement.The following example ensures that mathematical operators are serialized correctly (that is, for simplicity it outputs capital letters).
Note that this only has an effect on the actual serialization, not on output you generate with
xsl:result-document
.To also apply character-maps to this output, specify the
use-character-maps
attribute on the relevantresult-document
elements: