You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Alex Amies <AA...@access360.com> on 2001/03/23 07:17:27 UTC

Problems with UTF-8

I am having problems transforming UTF-8 documents.  I am inputing
double-byte (Chinese characters) with a UTF-8 XML document and
transforming them to HTML.  The double-byte characters are all output as
'?'.  I am using XalanJ2.01 with JDK1.2.2.05 on Solaris 8.

I have checked that the double-byte characters in the input XML document
have the correct characters by printing out the Unicode values.  I am
also displaying some parts of pages correctly in UTF-8 using JSP's by
looking up Chinese text from a ResourceBundle.  I was previously using
XalanJ1.2, with exactly the same xml / xsl combination and this
particular page was displayed correctly.  (Some other pages were not
displayed correctly with XalanJ1.2 and I hoped that moving up to a newer
version would solve the problem).  

The xml source, xsl stylesheet, and html output are listed below.  Sorry
for the voluminous listing.  I cannot find any documentation on specific
parameters to set in the TranformFactory.  Is there one for encoding?  

I am setting the ServletResponse contentType to "text/html;
charset=UTF-8", the xml encoding to "utf-8", and the xsl:output encoding
to "utf-8" using a tag in the xsl document.  Is there something else?
If anybody has any ideas or suggestions, please suggest.


************************************************************************
**

<?xml version="1.0" encoding="utf-8"?>
<loginPage>
<title>?? EnRole</title>
<form action="logon">
<input size="" value="zh_TW" type="hidden" name="language"/>
<input size="" value="TW" type="hidden" name="country"/>
<welcome/>
<a href="language">?????</a>
<formElement label="?????"><input size="" type="text"
name="logonID"/></formElement>
<formElement label="??"><input size="" type="password"
name="password"/></formElement>
<button><alt>?? EnRole</alt><image>login</image></button>
<submitLink href="question">??????</submitLink>
<submitLink href="help.jsp?action=logon">??</submitLink>
<detailedCopyright>Access360 ?? (c) 1999-2000 ??????</detailedCopyright>
</form>
<copyright>access360 ?? (c) 2000 ??????</copyright>
</loginPage> 

************************************************************************
**************************

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output
          method="html"
	  indent="yes"
	  encoding="utf-8"/>
  <xsl:param name="locale">en</xsl:param>

  <xsl:template match="loginPage">

    <html>
      <head>
        <script language="JavaScript" src="script_library.js"></script>
	<title>
	  <xsl:value-of select="title"/>
	</title>
        <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8"/>
        <link href="{$locale}/Styles.css" rel="stylesheet"
title="Styles" type="text/css"/>
      </head>

      <body bgcolor="ffffff" marginwidth="0" leftmargin="0"
marginheight="0" 
            topmargin="0">
	<table border="0" cellPadding="0" cellSpacing="0" width="100%">
	  <tr>
	    <td bgcolor="white">
	      <img src="{$locale}/images/logo.gif"/>
	    </td>
            <td bgcolor="white" align="right">
              <xsl:apply-templates select="customerLogo"/>
	    </td>
          </tr>

	  <!-- Top Blue Row -->
	  <tr>
	    <td class="topnavigation" colspan="2">
	      <img src="images/pixel.gif" height="1" width="5"
align="left" border="0"/>
              <img src="images/pixel.gif" height="29"/>
              <img src="images/pixel.gif" height="1" width="14"
border="0"/>
	    </td>
	  </tr>

	  <!-- Header Graphic -->
	  <tr>
	    <td class="topheader" colspan="2">
              <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                  <td width="100%" height="36">
                    <xsl:choose>
                      <xsl:when test="headerImage">
	                <img src="{$locale}/images/{headerImage}.gif"
border="0"/>
                      </xsl:when>
                      <xsl:otherwise>
	                <img src="{$locale}/images/headerlogin.gif"
border="0"/>
                      </xsl:otherwise>
                    </xsl:choose>
                  </td>
                </tr>
              </table>
	    </td>
	  </tr>

	  <xsl:apply-templates select="form|languageList"/>

	  <!-- Inner bar for lower part of page -->
	  <tr>
	    <td height="9" bgcolor="cccc99" colspan="2">
	      <img src="images/pixel.gif" width="1" height="9"
border="0"/>
	    </td>
	  </tr>

	  <xsl:apply-templates select="copyright"/>
	</table>
      </body>
    </html>

  </xsl:template>

  <!-- template for displaying customer logo -->
  <xsl:template match="customerLogo">
    <xsl:choose>
      <xsl:when test="url">
        <a href="{url}">
          <img src="images/{img}" border="0"/>
        </a>
      </xsl:when>
      <xsl:otherwise>
        <img src="{img}" border="0"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Template for login form -->
  <xsl:template match="form">
    <tr>
      <td width="100%" class="login" colspan="2">
        <img src="images/pixel.gif" width="1" height="36"
border="0"/><br/>
        <img src="images/pixel.gif" width="155" height="100" border="0"
align="left"/>
	<table cellpadding="0" cellspacing="0" border="0">
	  <xsl:apply-templates
select="welcome|incorrectLoginMessage|cue"/>
	  <tr>
	    <td width="275" class="submitLink" cellvalign="bottom">
              <xsl:apply-templates select="a"/>
	    </td>
	    <td nowrap="true"><br/>
	      <form name="logon" action="{@action}" method="POST"
accept-charset='UTF-8'>

                <!-- Set the timezone offset -->
                <input type="hidden" name="timezoneOffset"/>

                <table cellpadding="0" cellspacing="0" border="0">
  	          <xsl:apply-templates select="formElement"/>
  	          <xsl:apply-templates
select="button|submitLink|text|input"/>
                </table>
	      </form>
	    </td>
	  </tr>
	  <xsl:apply-templates select="detailedCopyright"/>
	</table>
      </td>
    </tr>
  </xsl:template>

  <!-- template for displaying welcome message -->
  <xsl:template match="welcome">
    <tr>
      <td class="login" colspan="2" align="left">
        <img border="0" src="{$locale}/images/welcome.gif"/>
      </td>
    </tr>
  </xsl:template>

  <!-- template for displaying incorrect login message and cues-->
  <xsl:template match="incorrectLoginMessage">
    <tr>
      <td colspan="2">
        <b class="loginform">
          <xsl:apply-templates/> 
        </b>
      </td>
    </tr>
  </xsl:template>

  <!-- template for displaying text entry and password fields -->
  <xsl:template match="formElement">
    <tr>
      <td>
        <b class="loginform">
          <xsl:value-of select="@label"/>:&#xa0;
        </b>
      </td>
      <td class="loginform" align="right">
          <xsl:apply-templates/> 
        <br/>
      </td>
    </tr>
  </xsl:template>

  <!-- template for displaying text for Q&A -->
  <xsl:template match="data">
    <span class="form">
      <xsl:apply-templates/> 
    </span>
    <br/>
  </xsl:template>

  <!-- template for displaying buttons -->
  <xsl:template match="button">
    <tr>
      <td align="right" colspan="2">
        <a
onmouseover="document.images['logon'].src='{$locale}/images/{image}_f2.g
if'; window.status='{alt}'; return true" 
 
onmouseout="document.images['logon'].src='{$locale}/images/{image}.gif';
window.status=location; return true" 
           href="Javascript:submitLogon();">
          <img alt="{alt}" src="{$locale}/images/{image}.gif" 
	       name="logon" border="0" vspace="4"/>
        </a>
      </td>
    </tr>
  </xsl:template>

  <!-- template for links that are used to submit data (eg forgot
password) -->
  <xsl:template match="submitLink">
    <tr>
      <td align="right" colspan="2">
          <a href="Javascript:submitForm(document.forms['logon'],
'{@href}');" 
             style="text-decoration:underline;"
             onmouseover="window.status='{.}'; return true"
             onmouseout="window.status=location; return true">
            <xsl:value-of select="."/>
          </a>
      </td>
    </tr>
  </xsl:template>

  <!-- Copy XHTML elements -->
  <xsl:template match="input|br">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <!-- template for detailed copyright message -->
  <xsl:template match="detailedCopyright">
    <tr>
      <td colspan="2">
        <br/>
        <span style="font-family:verdana; font-size:8pt;">
	  <xsl:apply-templates/>
        </span>
      </td>
    </tr>
  </xsl:template>

  <!-- template for general copyright message -->
  <xsl:template match="copyright">
    <tr>
      <td class="copyright" colspan="2">
	<xsl:apply-templates/>
      </td>
    </tr>
  </xsl:template>

  <!-- Copy and underline anchors -->
  <xsl:template match="a">
    <a>
      <xsl:for-each select="@*">
        <xsl:attribute name="{name()}">
          <xsl:value-of select="."/>
        </xsl:attribute>
      </xsl:for-each>
      <xsl:attribute
name="style">text-decoration:underline</xsl:attribute>
      <xsl:apply-templates/>
    </a>
  </xsl:template>

  <!-- Template for list of languages -->
  <xsl:template match="languageList">
    <tr>
      <td class="login" colspan="2">
        <br/>
        <table width="400" align="left" border="0">
          <xsl:apply-templates select="cue"/>
          <xsl:apply-templates select="language"/>
        </table>
      </td>
   </tr>
  </xsl:template>

  <!-- Template for cues -->
  <xsl:template match="cue">
    <tr>
      <td>
        <img src="images/pixel.gif" width="250" height="1"/>
      </td>
      <td class="login" align="left" nowrap="true" border="0">
        <span class="logoncue">
          <xsl:apply-templates/>
        </span>
      </td>
      <td></td>
    </tr>
  </xsl:template>

  <!-- Template for individual languages -->
  <xsl:template match="language">
    <tr>
      <td>
        <img src="images/pixel.gif" width="250" height="1"/>
      </td>
      <td align="right">
        <a href="logon?language={localeString}&amp;country={country}" 
 
onMouseOut="document.images['{image}'].src='{image}.gif';window.status=l
ocation; return true;" 
 
onMouseOver="document.images['{image}'].src='{image}_f2.gif';window.stat
us='{alt}'; return true;">
          <img src="{image}.gif" border="0" name="{image}" alt="{alt}"/>
          </a>
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet>

************************************************************************
****************************************

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="script_library.js" language="JavaScript"></script>
<title>?? EnRole</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<link type="text/css" title="Styles" rel="stylesheet"
href="zh_TW/Styles.css">
</head>
<body topmargin="0" marginheight="0" leftmargin="0" marginwidth="0"
bgcolor="ffffff">
<table width="100%" cellSpacing="0" cellPadding="0" border="0">
<tr>
<td bgcolor="white"><img src="zh_TW/images/logo.gif"></td><td
align="right" bgcolor="white"></td>
</tr>
<tr>
<td colspan="2" class="topnavigation"><img border="0" align="left"
width="5" height="1" src="images/pixel.gif"><img height="29"
src="images/pixel.gif"><img border="0" width="14" height="1"
src="images/pixel.gif"></td>
</tr>
<tr>
<td colspan="2" class="topheader">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="36" width="100%"><img border="0"
src="zh_TW/images/headerlogin.gif"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" class="login" width="100%"><img border="0" height="36"
width="1" src="images/pixel.gif"><br>
<img align="left" border="0" height="100" width="155"
src="images/pixel.gif"><table border="0" cellspacing="0"
cellpadding="0">
<tr>
<td align="left" colspan="2" class="login"><img
src="zh_TW/images/welcome.gif" border="0"></td>
</tr>
<tr>
<td cellvalign="bottom" class="submitLink" width="275"><a
href="language" style="text-decoration:underline">?????</a></td><td
nowrap="true">
<br>
<form accept-charset="UTF-8" method="POST" action="logon" name="logon">
<input name="timezoneOffset" type="hidden">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b class="loginform">?????:&nbsp;
        </b></td><td align="right" class="loginform"><input size=""
type="text" name="logonID">

<br>
</td>
</tr>
<tr>
<td><b class="loginform">??:&nbsp;
        </b></td><td align="right" class="loginform"><input size=""
type="password" name="password">

<br>
</td>
</tr>
<input size="" value="zh_TW" type="hidden" name="language"><input
size="" value="TW" type="hidden" name="country">
<tr>
<td colspan="2" align="right"><a href="Javascript:submitLogon();"
onmouseout="document.images['logon'].src='zh_TW/images/login.gif';
window.status=location; return true"
onmouseover="document.images['logon'].src='zh_TW/images/login_f2.gif';
window.status='?? EnRole'; return true"><img vspace="4" border="0"
name="logon" src="zh_TW/images/login.gif" alt="?? EnRole"></a></td>
</tr>
<tr>
<td colspan="2" align="right"><a onmouseout="window.status=location;
return true" onmouseover="window.status='??????'; return true"
style="text-decoration:underline;"
href="Javascript:submitForm(document.forms['logon'],%20'question');">???
???</a></td>
</tr>
<tr>
<td colspan="2" align="right"><a onmouseout="window.status=location;
return true" onmouseover="window.status='??'; return true"
style="text-decoration:underline;"
href="Javascript:submitForm(document.forms['logon'],%20'help.jsp?action=
logon');">??</a></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="2">
<br>
<span style="font-family:verdana; font-size:8pt;">Access360 ?? (c)
1999-2000 ??????</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" bgcolor="cccc99" height="9"><img border="0" height="9"
width="1" src="images/pixel.gif"></td>
</tr>
<tr>
<td colspan="2" class="copyright">access360 ?? (c) 2000 ??????</td>
</tr>
</table>
</body>
</html>


Alex Amies
Research and Development
Tel (949) 255-3302
Tel (877) 742-6400
Fax (949) 255-3121
www.access360.com
 
access360
A Better Way to Manage Access Rights