Can I use a character map for >

Here should go questions about transforming XML with XSLT and FOP.
ann.jensen
Posts: 313
Joined: Wed Jun 17, 2015 10:19 am

Can I use a character map for >

Post by ann.jensen »

Hi,
My XSLT transform based on DITA-OT 1.7.5 (not written by me) takes source XML like

Code: Select all

 <sectiondiv outputclass="string_text">
        &lt;iframe
              src="https://player.vimeo.com/video/785670628"
              style="max-width:437px" width="100%" height="246" frameborder="0" allow="autoplay;
              fullscreen; picture-in-picture" allowfullscreen&gt;&lt;/iframe&gt;
        </sectiondiv>
and outputs

Code: Select all

      <text><![CDATA[
        &lt;iframe
              src="https://player.vimeo.com/video/785670628"
              style="max-width:437px" width="100%" height="246" frameborder="0" allow="autoplay;
              fullscreen; picture-in-picture" allowfullscreen&gt;&lt;/iframe&gt;
        ]]></text>
The output for the XSLT is set to XML and the main templates are

Code: Select all

  
  <xsl:template match="//sectiondiv[@outputclass='string_text']" mode="XML">
    <text>
      <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
      <xsl:apply-templates />
      <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
    </text>
  </xsl:template>
  
   <xsl:template match="*" mode="XML">
    <xsl:copy copy-namespaces="no">
      <xsl:copy-of select="@*[name(.)!='class']" copy-namespaces="no"/>
      <xsl:apply-templates mode="XML"/>
    </xsl:copy>
  </xsl:template>
 
Instead I want output with < and >

Code: Select all

      <text><![CDATA[
        <iframe
              src="https://player.vimeo.com/video/785670628"
              style="max-width:437px" width="100%" height="246" frameborder="0" allow="autoplay;
              fullscreen; picture-in-picture" allowfullscreen></iframe>
        ]]></text>
Should I be able to use a character map to do this conversion e.g.

Code: Select all

  <xsl:character-map name="cm">
    <xsl:output-character character="&lt;" string="&lt;"/>   
    <xsl:output-character character="&gt;" string="&gt;"/>    
  </xsl:character-map>

  <xsl:output method="xml" version="1.1" indent="yes" cdata-section-elements=" required-cleanup " use-character-maps="cm"/>
Any advice appreciated,
Regards,
Ann
Martin Honnen
Posts: 101
Joined: Tue Aug 19, 2014 12:04 pm

Re: Can I use a character map for &gt;

Post by Martin Honnen »

Instead of using apply-templates, I would suggest to use the serialize function e.g.

Code: Select all

<xsl:value-of select="serialize(node(), map { 'method' : 'xml' })"/>
Post Reply