2

The xml was like this:

< cell i='0' j='0' vi='0' parity='Odd' subType='-1'> & #34;String& #39;</cell> 

But after the intepretion of the xsl, the output is like this:

< td nowrap="true" class="gridCell" i="0" j="0">"String'< /td>

I would like to keep the & #34; and & #39;. I've tried character map,but it doesn't work. The code is like this:

      < xsl:character-map name="raquo.ent">

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

< xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" use-character-maps="raquo.ent"/>

Can anyone help? Thank you very much!

Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
Jamie
  • 85
  • 1
  • 8

1 Answers1

1

This transformation:

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:output omit-xml-declaration="yes" indent="yes"
    use-character-maps="raquo.ent"/>

    <xsl:character-map name="raquo.ent">
     <xsl:output-character character="&#34;" string='&amp;#34;'/>
     <xsl:output-character character="&#39;" string='&amp;#39;'/>
    </xsl:character-map>

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

when applied on the provided XML document:

<cell i='0' j='0' vi='0' parity='Odd' subType='-1'>&#34;String&#39;</cell>

produces the wanted, correct result:

<cell i="0" j="0" vi="0" parity="Odd" subType="-1">&#34;String&#39;</cell>
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • @Dimitre Novatchev thank you, but how do you test it? It still doesn't work here:( – Jamie May 24 '11 at 13:45
  • @Jamie: I always test my solutions -- this one was run with Saxon 9.1.07 and XQSharp. If you're running Altova, file a bug to them. – Dimitre Novatchev May 24 '11 at 13:53
  • @Dimitre Novatchev It seems that the character-map doesn't work in XSLT 1.0.It's not valid for the pages. What can I do? – Jamie May 24 '11 at 15:28
  • @Jamie: Yo need to install and use an XSLT 2.0 processor. `` is an XSLT2.0 - only feature. – Dimitre Novatchev May 24 '11 at 16:12
  • @Dimitre Novatchev: As this is from a project of our company, I don't know whether it will support XSLT 2.0. Do you know any other method other than the character-map? – Jamie May 24 '11 at 16:33
  • @Jamie: I asked a similar question: http://stackoverflow.com/questions/5985615/preserving-entity-references-when-transforming-xml-with-xslt I ended up not using XSLT for this particular task, but as a really ugly work-around you could try pre-processing your instance and replacing every `&` with `&` so your entities look like `&#34;`. You would then need to post process your instance after your XSLT transform and replace all `&` with `&`. – Daniel Haley May 24 '11 at 16:57