xsl-list
[Top] [All Lists]

CDATA / UTF-8 / Special Characters

2005-09-21 11:41:12
Forgive me if this is a simple question I am rather new to xslt.  I have
a java program that uses the Xalan processor to translate xml into html.
There are two translations that happen and the output of the first is
wrapped in a CDATA section and used as the input for the second (See
below).

The data for the first xml listed below comes from a database that was
originally entered by copy/paste from a word document.  So the single
and double quotes are the word version.

The first translation works perfectly but the second translation somehow
destroys the single and double quotes and other characters.  So when I
output them to the browser they show up as ? (question marks/invalid
characters).  Xalan is set to use utf8 for the encoding and all the
xml/xslt documents have utf8 encoding declared.  Anyone have any ideas?

Thanks for the help.

/********************* XML1 **************************************/
<?xml version="1.0" encoding="UTF-8"?> 
<ARTICLE>
    <TITLE>This is the title</TITLE>
    <BODY>This is the &lt;bold&gt;body&lt;/bold&gt; of an
article.</BODY> <!-- This may contain html. -->
</ARTICLE>


Gets translated using something like


/******************************** XSLT1 *****************************/
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

<xsl:template match="ARTICLE">
   <span><xsl:value-of select="TITLE" disable-output-escaping="yes"
/></span>
   <div><xsl:value-of select="BODY" disable-output-escaping="yes"
/></div>
</xsl:template>
</xsl:stylesheet>



Then combined in java to form a new xml document like

/************************** XML2 ******************************/
<?xml version="1.0" encoding="UTF-8"?>
<PAGE>
<WIDGET POSITION="1" RANK="1"><![CDATA[
<span>This is the title</span>
<div>This is the <bold>body</bold> of an article.</div>
]]></WIDGET>
</PAGE>

Translated using 

/************** XSLT2 *******************************************/
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";


<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:template match="PAGE">
<html>
<head>
</head>
<body>
  <table cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td></td>
    <td>
    <xsl:for-each select="WIDGET[(_at_)POSITION=1]">
      <xsl:sort select="@RANK" data-type="number" order="ascending" />
      <xsl:value-of select="." disable-output-escaping="yes" /> 
    </xsl:for-each>
    </td>
    <td></td>
    <td></td>
  </tr>
  </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>