php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30969 XSLTProcessor Not Recognizing DOMDocument Root
Submitted: 2004-12-03 00:46 UTC Modified: 2004-12-03 11:49 UTC
From: c dot d at earthlink dot net Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.0.2 OS: Mac OS X 10.3.6
Private report: No CVE-ID: None
 [2004-12-03 00:46 UTC] c dot d at earthlink dot net
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-03 08:51 UTC] chregu@php.net
Your XSLT is wrong.. It needs to be 

	<xsl:value-of select="root/fullname"/>

Your approach doesn't even work with xsltproc on the commandline.

and
"If identical xml is loaded from a file via DOMDocument->load the XSLT
processor processes the root element correctly."

Definitively not here on my system 
 [2004-12-03 11:49 UTC] c dot d at earthlink dot net
Is not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 00:01:30 2024 UTC