[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] CDATA / UTF-8 / Special Characters


Subject: RE: [xsl] CDATA / UTF-8 / Special Characters
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 22 Sep 2005 18:54:05 +0100

I don't see any single quotes in this example, or any double quotes in
places that are relevant to the problem. 

Perhaps, given that your data originates in Word, it is using "typographical
quotes" rather than ordinary ASCII quotes. These are notoriously troublesome
because they have a different encoding in Windows CP1252 from the standard
Unicode encoding. Check therefore that when you say your XML is encoded in
UTF-8, it really is.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Erkkila, Matthew [mailto:ErkkilaM@xxxxxxxxxxxx] 
> Sent: 21 September 2005 19:41
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] CDATA / UTF-8 / Special Characters
> 
> 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[@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>


Current Thread
Keywords