My application is performing a series of XML to XML transformations. It is essential that the &quot; and &apos; metacharacters be preserved after each transformation. However, I find that while the < > & characters are expanded, saxon (and xalan) will not expand the ‘ “  characters in the output serialization. If character maps (or entity property files) are used, the mappings have the effect of turning off the expansion for the XML metacharacters. For example, if I create a mapping from &#62; to &lt; the output element will contain the < character, not the &lt; I expect. (The mappings work as advertised for characters that are not XML metacharacters.)

 

What is the reason for this behavior and what is the simplest way to ensure that the five XML metacharacters will be expanded?

 

Wayne Johnson

 

saxon 7.9.1

 

input file

<test>

<e1> &apos; &lt; &gt; &amp; &quot; </e1>

<e2> &#65; </e2>

</test>

 

output file

<?xml version="1.0" encoding="UTF-8"?>

<test>

   <e1> ' < &gt; &amp; " </e1>

   <e2> AAA </e2>

</test>

 

stylesheet

<xsl:stylesheet version="2.0"

  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output

    encoding='UTF-8'

    method='xml'

    indent="yes"

    use-character-maps="mycharmap"/>

  <xsl:strip-space elements="*"/>

 

  <xsl:character-map name="mycharmap">

<!--    <xsl:output-character character="&#34;" string="&quot;"/>-->

<!--    <xsl:output-character character="&#38;" string="&amp;"/>-->

<!--    <xsl:output-character character="&#39;" string="&apos;"/>-->

    <xsl:output-character character="&#60;" string="&lt;"/>

<!--    <xsl:output-character character="&#62;" string="&gt;"/>-->

    <xsl:output-character character="&#65;" string="AAA"/>

  </xsl:character-map>

 

  <xsl:template match="node() | @*">

    <xsl:copy>

      <xsl:apply-templates select="node() | @*"/>

    </xsl:copy>

  </xsl:template>

 

</xsl:stylesheet>