|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51842 XSLTProcessor doesn't accept dynamics DOMDocuments as XSLT
Submitted: 2010-05-17 16:58 UTC Modified: 2010-05-18 02:29 UTC
From: superruzafa at gmail dot com Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
 [2010-05-17 16:58 UTC] superruzafa at gmail dot com
When trying to use XSLTProcessor::importStyleSheet() with a dynamically generated DOMDocument an error occurs.

The workaround I found is save the DOMDocument for the XSLT in a string a load it again as string.

Test script:
$xml = new DOMDocument("1.0", "UTF-8");
$root = $xml->createElement("foo");
$root->setAttribute("xmlns", "");

$xslt = new DOMDocument("1.0", "UTF-8");
$stylesheet = $xslt->createElement("xsl:stylesheet");
$stylesheet->setAttribute("version", "1.0");
$stylesheet->setAttribute("xmlns:foons", "");
$stylesheet->setAttribute("xmlns:xsl", "");

$template = $xslt->createElement("xsl:template");
$template->setAttribute("match", "/");

//workaround: $xslt->loadXML($xslt->saveXML());

$xsltProc = new XSLTProcessor();
echo $xsltProc->transformToDoc($xml)->saveXML();

Expected result:
<?xml version="1.0"?>

Actual result:
Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: compilation error: element xsl:stylesheet in /var/www/xslt/public_html/xslt.php on line 23

Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: xsltParseStylesheetProcess : document is not a stylesheet in /var/www/xslt/public_html/xslt.php on line 23

Warning: XSLTProcessor::transformToDoc() [xsltprocessor.transformtodoc]: No stylesheet associated to this object in /var/www/xslt/public_html/xslt.php on line 24

Fatal error: Call to a member function saveXML() on a non-object in /var/www/xslt/public_html/xslt.php on line 24


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-18 02:29 UTC]
-Status: Open +Status: Bogus
 [2010-05-18 02:29 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

a proper namespaced document created using the dom level 2 methods is required
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 08 23:01:23 2021 UTC