From:             memoimyself at yahoo dot com dot br
Operating system: Windows XP
PHP version:      5.1.2
PHP Bug Type:     XSLT related
Bug description:  transformToXML will NOT output UTF-8

Description:
------------
An instance of the XSLTProcessor class, via its transformToXML method, is
used to transform XML documents using an XSL stylesheet.

The XSL document is in a file that is encoded in UTF-8. 

The PHP script is in a file also encoded in UTF-8.

The XML documents are created at run time from XML strings stored in a
MySQL 5 database whose character set is
UTF-8 and whose tables all have UTF-8 as their character set as well.

All the XML strings stored in the database are duly encoded in UTF-8.

Prior to data retrieval, a 'SET NAMES "utf8"' query is run to ensure that
all i/o operations use the UTF-8 character set.

Upon transformation, the results are output to the client preceded by
"header('Content-Type: text/html; charset=UTF-8')" to ensure that the
browser uses the correct character set.

The XSL file has the following top-level (child node of the document
element, as it should be) element:

<xsl:output encoding="utf-8" method="html"/>

When this code is run on a Windows server (Win XP, Apache 2.0.55,PHP
5.1.2), the transformation NEVER outputs UTF-8 text (seems to output
iso-8859-1), even if the 'method' attribute in the above element is
changed to 'xml', and even if a 'media-type' attribute is also used.

When run on a Linux server (also running PHP 5.1.2), the transformation
runs as expected and outputs proper UTF-8 text to the browser.

Reproduce code:
---------------
PHP code:

$dbo = new PDO(BD_DSN, BD_USERNAME, BD_PWD);
$dbo->query('SET NAMES "utf8"');
$sql = 'SELECT Report FROM reports WHERE Id =
'.$dbo->quote(strip_gpc_slashes($_GET['rid'])).' 
AND Author = '.$dbo->quote($_SESSION['user']);
$result = $dbo->query($sql);
$row = $result->fetch(PDO::FETCH_OBJ);
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->loadXML($row->Report);
$xsl = new DOMDocument('1.0', 'UTF-8');
$xsl->load('/path/to/xsl/file.xsl');
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);
$output = $proc->transformToXML($xml);
header('Content-Type: text/html; charset=utf-8');
print $output;

Start of XSL document:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.w3.org/2005/11/schema-for-xslt20.xsd";>
        <xsl:output encoding="utf-8" method="html"/>
        <xsl:template match="/">...

Expected result:
----------------
All text output to the browser should be proper UTF-8. If the browser's
character encoding is set to UTF-8 (which it should, with the
"content-type" header above), all accented character should be adequately
displayed.

Actual result:
--------------
When the code is run on a Windows XP server, the text output to the
browser is NOT proper UTF-8 and all accented characters are replaced by
weird symbols.

When the code is run on a Linux server (also equipped with PHP 5.1.2),
everything works as expected and the output is proper UTF-8.

-- 
Edit bug report at http://bugs.php.net/?id=36415&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36415&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36415&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36415&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36415&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36415&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36415&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36415&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36415&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36415&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36415&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36415&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36415&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36415&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36415&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36415&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36415&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36415&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36415&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36415&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36415&r=mysqlcfg

Reply via email to