|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-12-03 08:51 UTC] chregu@php.net
[2004-12-03 11:49 UTC] c dot d at earthlink dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 15:00:02 2025 UTC |
Description: ------------ If xml is created via a DOMDocument and then sent to a XSLTProcessor with a XSL file, the following xsl code doesn't find the root node: <xsl:template match="/"> <xsl:value-of select="childofroot"/> </xsl:template> You have to create a template for the root element (using it's name) and use an apply-templates tag instead of value-of tag(s) in the root template (such as above). If identical xml is loaded from a file via DOMDocument->load the XSLT processor processes the root element correctly. Reproduce code: --------------- <?php $temp_DOM = new DomDocument("1.0"); $root = $temp_DOM->createElement("root"); $root = $temp_DOM->appendChild($root); $element = $temp_DOM->createElement("fullname"); $element = $root->appendChild($element); $text = $temp_DOM->createTextNode("John Doe"); $text = $element->appendChild($text); $xsl_DOM = new DOMDocument; $xsl_DOM->load("test.xsl"); $xslt = new XSLTProcessor(); $xslt->importStylesheet($xsl_DOM); echo $xslt->transformToXML($temp_DOM); ?> Contents of XSL File <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml"/> <xsl:template match="/"> <xsl:value-of select="fullname"/> </xsl:template> </xsl:stylesheet> Expected result: ---------------- Should output xml declaration and value of "fullname" element. Actual result: -------------- Only outputs xml declaration. Value of "fullname" element is not output.