|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-05-18 02:29 UTC] rrichards@php.net
-Status: Open
+Status: Bogus
[2010-05-18 02:29 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 13:00:01 2025 UTC |
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