Reputation: 53
Need to convert all unicode(~) of an XML to iso(˜) from an XML(entities.xml) where all these values are stroed....
entities.xml:-
<entities>
<entity iso="eacute" unicode="x00e9"/>
<entity iso="iacute" unicode="x00ed"/>
</entities>
Input:-
<?xml version="1.0" encoding="UTF-8"?>
<chapter>
<title>Chaptér Tilté</title>
<body>
<p>Thís is téxt...</p>
<p>Thís is téxt...</p>
<p>Thís is téxt...</p>
<p>Thís is téxt...</p>
<p>Thís is téxt...</p>
</body>
</chapter>
Output should be :-
<chapter>
<title>Chaptér Tilté</title>
<body>
<p>Thís is téxt...</p>
<p>Thís is téxt...</p>
<p>Thís is téxt...</p>
<p>Thís is téxt...</p>
<p>Thís is téxt...</p>
</body>
There are many other values are also in entities.xml like....
<entity iso="nbsp" unicode="x00a0"/>
<entity iso="ordf" unicode="x00aa"/>
<entity iso="ordm" unicode="x00ba"/>
<entity iso="para" unicode="x00b6"/>
<entity iso="plusmn" unicode="x00b1"/>
<entity iso="pound" unicode="x00a3"/>
<entity iso="raquo" unicode="x00bb"/>
<entity iso="reg" unicode="x00ae"/>
<entity iso="sect" unicode="x00a7"/>
Upvotes: 2
Views: 728
Reputation: 7173
You can achieve that using xslt-2.0 using character-map.
Try the following stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:character-map name="CharMap">
<xsl:output-character character="í" string="&iacute;"/>
<xsl:output-character character="é" string="&eacute;"/>
</xsl:character-map>
<xsl:output indent="yes" use-character-maps="CharMap"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Upvotes: 2