php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29087 DOM + XSL extension doesn't expand entities
Submitted: 2004-07-10 18:25 UTC Modified: 2004-07-10 18:59 UTC
From: x-penguin at tut dot by Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5CVS-2004-07-10 (dev) OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: x-penguin at tut dot by
New email:
PHP Version: OS:

 

 [2004-07-10 18:25 UTC] x-penguin at tut dot by
Description:
------------
When attempting to do an XSL transformation using the new DOM and XSL extensions available in PHP 5 RC 3, I've noticed entities are not expanded in the output. If I import the DOM object into SimpleXML, the entities are expanded.

I run Apache/2.0.48 (Unix). I don't recall 
seeing any errors when I built and installed Apache, 
PHP, libxml2, or libxslt.

libxslt 1.1.8
libxml 	2.6.11
php5cvs-2004-07-10

./configure --prefix=/usr --sysconfdir=/etc/ --with-apxs2 --with-config-file-path=/etc --with-zlib --with-bz2 --enable-ftp --with-gettext --with-iconv --with-mysql=/usr --with-ncurses --enable-mbstring=ru --enable-mbregex --enable-mbstr-enc-trans --with-png --with-pgsql --disable-short-tags --with-xsl --with-libxml --with-gd --without-sqlite

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;

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

$xmlDocument = simplexml_import_dom($xmlDOM);
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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-10 18:59 UTC] chregu@php.net
You have to use

$xmlDOM->substituteEntities = true;

before $xmlDOM->loadXML()


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC