php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66937 XSLTProcessor::transformToDoc causes separation of doctype and source document
Submitted: 2014-03-20 17:55 UTC Modified: 2020-06-12 14:11 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: sites at hubmed dot org Assigned: cmb (profile)
Status: Assigned Package: XSLT related
PHP Version: 5.5.10 OS: OS X
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-03-20 17:55 UTC] sites at hubmed dot org
Description:
------------
Calling XSLTProcessor::transformToDoc (which would be expected not to alter the source document) on a DOMDocument that has a doctype causes the doctype to be somehow "separated" from the document, so that the doctype is no longer included when writing out the original document.

A workaround is to clone the DOMDocument object before calling transformToDoc on it, but this shouldn't be necessary.

I notice that the "nextSibling" property of the DOMDocumentType object is lost during the transformation.

=====

Tested with PHP 5.5.10 and 5.4.24.

libxml2 Version => 2.9.0
libxslt Version => 1.1.28

Test script:
---------------
https://gist.github.com/hubgit/9669288

Input:
<?xml version="1.0"?>
<!DOCTYPE article PUBLIC "-//example//EN" "http://example.org/dtd">
<article/>


Expected result:
----------------
<?xml version="1.0"?>
<!DOCTYPE article PUBLIC "-//example//EN" "http://example.org/dtd">
<article/>

Actual result:
--------------
<?xml version="1.0"?>
<article/>

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-12 14:11 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-06-12 14:11 UTC] cmb@php.net
I can confirm the reported behavior. xsltApplyStylesheetUser()
removes the DTD from the given document, which is surprising to
me, but will probably not change in libxslt[1].

[1] <https://mail.gnome.org/archives/xslt/2020-June/msg00001.html>
 [2020-06-12 14:14 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #66937: transformToDoc() removes DTD of source document
On GitHub:  https://github.com/php/php-src/pull/5704
Patch:      https://github.com/php/php-src/pull/5704.patch
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Jul 09 12:01:29 2020 UTC