php.net |  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
Description:
------------
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", "http://example.com");
$xml->appendChild($root);

$xslt = new DOMDocument("1.0", "UTF-8");
$stylesheet = $xslt->createElement("xsl:stylesheet");
$stylesheet->setAttribute("version", "1.0");
$stylesheet->setAttribute("xmlns:foons", "http://example.com");
$stylesheet->setAttribute("xmlns:xsl", "http://www.w3.org/1999/XSL/Transform");
$xslt->appendChild($stylesheet);

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

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

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


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


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


Patches

Pull Requests

History

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

a proper namespaced document created using the dom level 2 methods is required
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 13:01:30 2024 UTC