|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31062 Wrong XSLT with xmlns.
Submitted: 2004-12-12 00:34 UTC Modified: 2004-12-16 08:37 UTC
From: swappp at yandex dot ru Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.0.2 OS:
Private report: No CVE-ID: None
 [2004-12-12 00:34 UTC] swappp at yandex dot ru
It works normal...

Reproduce code:
$xml_doc_node = new DOMDocument('1.0', "UTF-8");
$xml_style = $xml_doc_node->createProcessingInstruction('xml-stylesheet');
$xml_style->nodeValue = 'href="html.xsl" type="text/xsl"';
$xml_page = $xml_doc_node->createElement('document');
$element = $xml_page->appendChild(new DOMElement('old-html'));
$div = $element->appendChild(new DOMElement('div', 'test'));
$xsl = DOMDocument::loadXML('<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns="" xmlns:xsl="" version="1.0"><xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="" indent="yes" encoding="UTF-8"/>
  <xsl:template match="/document">
    <html xmlns="" xml:lang="ru" lang="ru"><body><xsl:apply-templates/></body></html>
  <xsl:template match="/document/old-html"><xsl:copy-of select="*"/></xsl:template>
$proc = new xsltprocessor;
echo $proc->transformToXML($xml_doc_node);

Expected result:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="ru" lang="ru">

Actual result:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="ru" lang="ru">
    <div xmlns="" xmlns="">test</div>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-14 17:13 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

non-namespace aware functions used
 [2004-12-15 18:48 UTC] swappp at yandex dot ru
But it is the simplified code.
$dom_html = DOMDocument::loadHTML('<div xmlns="">'.$content.'</div>');
$xp = new DOMXPath($dom_html);
$body = $xp->query("/html/body/*");
foreach ($body as $tag)
  $tag = $element->appendChild($element->ownerDocument->importNode($tag, true));

LoadHTML() don't support XHTML? And why loadHTML don't set document namespace?
P.S. Sorry for my bad English.
 [2004-12-16 08:37 UTC]
loadHTML is for HTML 4.0 documents, which have no namespace by specifications... If it's really XHTML, use loadXML

But your real problem is this:


That doesn't work. You can't set namespaces this way. There's no way actually in DOM to move an element from one namespace to another without rebuilding it .

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun May 16 16:01:23 2021 UTC