Page 1 of 1

Can I use a character map for >

Posted: Tue Dec 12, 2023 4:39 pm
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

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

Posted: Mon Dec 18, 2023 7:41 pm
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' })"/>