Reputation: 1020
I have the following XML:
<doc>
<chap>
>The bowler >delivers< the ball <
>to the batsman who attempts to <
>hit the ball " with his " bat away from <
>the fielders so he can run to the <
>other end of the pitch and score a run.<
</chap>
</doc>
I have to write some XSL to do some tasks to this input XML. But when I copy all nodes using...
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
...in the resulting file, instead of "
. In the resulting file those are converted to "
. I don't want that to happen.
<doc>
<chap>
>The bowler >delivers< the ball <
>to the batsman who attempts to <
>hit the ball " with his " bat away from <
>the fielders so he can run to the <
>other end of the pitch and score a run.<
</chap>
</doc>
Is there any method to keep "
as it is in the resulting XML?
Upvotes: 2
Views: 1131
Reputation: 7173
You can use xsl:use-character-maps
as shown below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output use-character-maps="CharMap"/>
<xsl:character-map name="CharMap">
<xsl:output-character character=""" string="&quot;"/>
</xsl:character-map>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Upvotes: 4