php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #24722 Losing entities during XSL transformation
Submitted: 2003-07-19 15:46 UTC Modified: 2004-08-07 18:18 UTC
From: el_profesorfr at yahoo dot fr Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.2 OS: SuSE Linux 7.3
Private report: No CVE-ID: None
 [2003-07-19 15:46 UTC] el_profesorfr at yahoo dot fr
Description:
------------
Hello,


When transforming an XML document with the DomXsltStylesheet object, references to local entities in the source XML doc do not pass through.
In the source code provided, I'm using page.xml as the source XML, sheet.xsl as the stylesheet, and transform.php as the PHP code of course.
The problem can be seen simply by issuing 'php transform.php' on the command line.

Hope I'm not missing something like an option, I'm not really an XML guru!

Environment:
- Linux SuSE 7.3
- Apache 2.0.47
- PHP 4.3.2
- libxml 2.5.8
- libxslt 1.0.31



Best regards,

Thomas

Reproduce code:
---------------
==== page.xml ====
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE old [
    <!ENTITY ccedil "&#231;">
]>
<old>&ccedil;a marche !</old>


==== sheet.xsl ====
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <new><xsl:apply-templates/></new>
    </xsl:template>
</xsl:stylesheet>


==== transform.php ====
<?
    $xml = domxml_open_file ('page.xml');
    $xsl = domxsl_xslt_stylesheet_file ('sheet.xsl');
    $out = $xsl->process ($xml, array ());
    $echo $xsl->result_dump_mem ($out);
?>

Expected result:
----------------
The output of 'php transform.php' should be:

<?xml version="1.0"?>
<new>&#xE7;a marche !</new>

(&#xE7 being the UTF-8 escape sequence for ?)

That's the output of the command 'xsltproc sheet.xsl page.xml' on the same machine.

Actual result:
--------------
You only get:

<?xml version="1.0"?>
<new>a marche !</new>

The '?' got lost somewhere down on the pipe...

PHP does the same thing when running as an Apache2 module.

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-21 05:52 UTC] rrichards@php.net
You need to use the undocumented flags when loading the document:
$xml = domxml_open_file('page.xml',DOMXML_LOAD_SUBSTITUTE_ENTITIES);
 [2003-07-21 11:56 UTC] el_profesorfr at yahoo dot fr
Yep, that works fine, thanks a lot!

However I noticed later that without the flag, most entity references in the body of the source XML would be stripped (my initial "bug" report), while on some occasions they would pass through unchanged (as if it were raw data).
I can provide a .xml + .xsl pair if you want to look at it any further, but I'm not sure if it deserves another bug report (might be a feature I didn't understand, or a bug in libx*, ...).

Thomas
 [2004-08-07 18:18 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Optional mode parameter was documented including possible values.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 17 15:01:29 2024 UTC