Edit report at http://bugs.php.net/bug.php?id=51842&edit=1

 ID:               51842
 Updated by:       rricha...@php.net
 Reported by:      superruzafa at gmail dot com
 Summary:          XSLTProcessor doesn't accept dynamics DOMDocuments as
                   XSLT
-Status:           Open
+Status:           Bogus
 Type:             Bug
 Package:          XSLT related
 Operating System: Linux
 PHP Version:      5.3.2

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2010-05-17 16:58:08] 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




------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51842&edit=1

Reply via email to