0

I have a xml input which is like that,

<xml>
<xrefline>&laquo;personne&raquo;&mdash;<cite.query w-pinpoint-page="xyz_abc_1_">abc(1)</cite.query></xrefline>
<xrefline>&laquo;abc&raquo;&mdash;<cite.query w-pinpoint-page="xyz_abc_1_">abc(1)</cite.query></xrefline>
</xml>

when I am adding cdata around the content of xrefline using xslt all the entities are changing to actual characters, is there a way that I should keep the output same?

so the output which I am getting is

<xml>
 <xrefline position="1"><![CDATA[«personne»—
         <cite.query w-pinpoint-page="xyz_abc_1_">123(1)</cite.query>]]>
      </xrefline>
 <xrefline position="2"><![CDATA[«abc»—
         <cite.query w-pinpoint-page="xyz_abc_1_">123(1)</cite.query>]]>
      </xrefline>
</xml>

The desire output which I am looking is

<xml>
 <xrefline position="1"><![CDATA[&laquo;personne&raquo;&mdash;
         <cite.query w-pinpoint-page="xyz_abc_1_">123(1)</cite.query>]]>
      </xrefline>
 <xrefline position="2"><![CDATA[&laquo;abc&raquo;&mdash;
         <cite.query w-pinpoint-page="xyz_abc_1_">123(1)</cite.query>]]>
      </xrefline>
</xml>

Here is the stylesheet

<xsl:stylesheet version="2.0" >
  <xsl:output indent="yes" method="xml" encoding="UTF-8"></xsl:output>
<xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
<xsl:template match="xrefline">
<xrefline>
        <xsl:attribute name="position">
          <xsl:value-of select="count(../preceding-sibling::xrefline)+1"/>
        </xsl:attribute>
        <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
            <xsl:copy-of select="node()" ></xsl:copy-of>
        <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
   </xrefline>
</xsl:template>

Any hint...

atif
  • 1,137
  • 7
  • 22
  • 35
  • 1
    If you wrap something in CDATA you are telling all downstream consumers to take the value as literal text. Your entities would cease to be entities and would become literal strings. You do not want to do this. – Jim Garrison Sep 30 '13 at 20:02
  • What to do in that case to get the desire output? – atif Sep 30 '13 at 20:33
  • 2
    Here's a related, if not duplicate, question: http://stackoverflow.com/questions/5985615/preserving-entity-references-when-transforming-xml-with-xslt – Daniel Haley Sep 30 '13 at 20:42
  • 1
    Daniel Haley is correct (not to mention that your entities in your source XML are not declared). – Kevin Brown Sep 30 '13 at 20:47
  • Thanks Daniel, got the hint and will implement it. – atif Oct 02 '13 at 18:43

0 Answers0