From:             
Operating system: Linux
PHP version:      5.3.2
Package:          XSLT related
Bug Type:         Bug
Bug description:XSLTProcessor doesn't accept dynamics DOMDocuments as XSLT

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 bug report at http://bugs.php.net/bug.php?id=51842&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51842&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51842&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=51842&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51842&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51842&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51842&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51842&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51842&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51842&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51842&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51842&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51842&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51842&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51842&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51842&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51842&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51842&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51842&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51842&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51842&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51842&r=mysqlcfg

Reply via email to