php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28826 SimpleXML expands entities but DOM + XSL does not
Submitted: 2004-06-18 11:09 UTC Modified: 2004-06-22 06:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: joe at joerags dot com Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5CVS-2004-06-18 (dev) OS: Mac OS 10.2.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 + 19 = ?
Subscribe to this entry?

 
 [2004-06-18 11:09 UTC] joe at joerags dot com
Description:
------------
When attempting to do an XSL transformation using the 
new DOM and XSL extensions available in PHP 5, I've 
noticed entities aren't expanded in the output. If I 
import the DOM object into SimpleXML, the entities are 
expanded.

The first time I attempted to run the following code I 
was using PHP 5 RC3, libxml2 2.6.10, and libxslt 1.1.7. 
I am now using CVS versions of PHP 5, libxml2, and 
libxslt in order to see if this was a bug fixed in 
either PHP 5, libxml2, or libxslt. The CVS versions I'm 
using were downloaded June 18th.

I run Apache 1.3.31 under Mac OS 10.2.8. I don't recall 
seeing any errors when I built and installed Apache, 
PHP, libxml2, or libxslt.

Reproduce code:
---------------
<?php
$xml = <<<EOD
<!DOCTYPE example [
<!ENTITY entity1 "Entity 1">
<!ENTITY entity2 "Entity 2">
]>
<example>
  <element1>Example Document</element1>
  <element2>&entity1;</element2>
  <element3>&entity2;</element3>
</example>
EOD;

$xsl = <<<EOD
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="example">
    <p>XSL Element 1: <xsl:value-of select="element1" /></p>
    <p>XSL Element 2: <xsl:value-of select="element2" /></p>
    <p>XSL Element 3: <xsl:value-of select="element3" /></p>
  </xsl:template>
</xsl:stylesheet>
EOD;

$xmlDocument = new DomDocument;
$xmlDocument->loadXML($xml);
$xslDocument = new DomDocument;
$xslDocument->loadXML($xsl);
$processor = new XsltProcessor;
$processor->importStyleSheet($xslDocument);
print $processor->transformToXML($xmlDocument);

$xmlDocument = simplexml_import_dom($xmlDocument);
print '<p>SimpleXML Element 1: ' . $xmlDocument->element1 . '</p>';
print '<p>SimpleXML Element 2: ' . $xmlDocument->element2 . '</p>';
print '<p>SimpleXML Element 3: ' . $xmlDocument->element3 . '</p>';
?>

Expected result:
----------------
XSL Element 1: Example Document

XSL Element 2: Entity 1

XSL Element 3: Entity 2

SimpleXML Element 1: Example Document

SimpleXML Element 2: Entity 1

SimpleXML Element 3: Entity 2

Actual result:
--------------
XSL Element 1: Example Document

XSL Element 2: 

XSL Element 3: 

SimpleXML Element 1: Example Document

SimpleXML Element 2: Entity 1

SimpleXML Element 3: Entity 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-22 06:19 UTC] joe at joerags dot com
I did the following and the test script I submitted 
works.

Using Fink (http://fink.sourceforge.net), I had it 
build and install libxml2 2.5.10 and libxslt 1.0.32. I 
then recompiled PHP 5 RC3 with these configuration 
commands: ./configure --prefix=/usr/local --with-zlib 
--with-libxml-dir=/sw --with-xsl=/sw --with-apxs=/usr/
sbin/apxs

The test script I submitted likely didn't work either 
because of user error on my part or a bug in something 
other than PHP.
 [2004-08-11 19:38 UTC] andrew at shh dot fi
I have the same problem as this person. I am using libxml 2.5.11 and libxslt 1.0.33. By the way this has only been tested on win32 (php 5).

Works fine with sablot but not with any of the domxml/xslt in 4 or 5.

Haven't found a solution yet which is big problem as can't move to php5 until it works
 [2004-08-11 19:45 UTC] andrew at shh dot fi
OK here its - the answer for 5 at the mo -

$xmldoc = new DomDocument(); 
$xmldoc->resolveExternals = TRUE;
$xmldoc->substituteEntities = TRUE;
$xmldoc->load($this->xml);
$xsldoc = new DomDocument(); 
$xsldoc->load($this->xsl);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 22:01:26 2024 UTC