Add CDATA to an xml file

You either need to do this:

<xsl:template match="teaserText_fr">
  <xsl:copy>
    <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
    <xsl:copy-of select="*"/>    
    <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
  </xsl:copy>
</xsl:template>

Or this:

<xsl:template match="teaserText_fr">
  <teaserText_fr>
    <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
    <xsl:copy-of select="*"/>    
    <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
  </teaserText_fr>
</xsl:template>

(I recommend the first approach)

and you should be all set.

To give the same treatment to any element whose name starts with “teaserText_”:

<xsl:template match="*[starts-with(local-name(), 'teaserText_')]">
  <xsl:copy>
    <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
    <xsl:copy-of select="*"/>    
    <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
  </xsl:copy>
</xsl:template>

Leave a Comment