php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: swappp at yandex dot ru
New email:
PHP Version: OS:

 

 [2004-12-12 00:34 UTC] swappp at yandex dot ru
Description:
------------
DOMDocument::load($xml_doc_node->saveXML());
It works normal...

Reproduce code:
---------------
$xml_doc_node = new DOMDocument('1.0', "UTF-8");
$xml_style = $xml_doc_node->createProcessingInstruction('xml-stylesheet');
$xml_doc_node->appendChild($xml_style);
$xml_style->nodeValue = 'href="html.xsl" type="text/xsl"';
$xml_page = $xml_doc_node->createElement('document');
$xml_doc_node->appendChild($xml_page);
$element = $xml_page->appendChild(new DOMElement('old-html'));
$div = $element->appendChild(new DOMElement('div', 'test'));
$div->setAttribute('xmlns','http://www.w3.org/1999/xhtml');
$xsl = DOMDocument::loadXML('<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent="yes" encoding="UTF-8"/>
  <xsl:template match="/document">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru"><body><xsl:apply-templates/></body></html>
  </xsl:template>
  <xsl:template match="/document/old-html"><xsl:copy-of select="*"/></xsl:template>
</xsl:stylesheet>');
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl);
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
  <body>
    <div>test</div>
  </body>
</html>

Actual result:
--------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
  <body>
    <div xmlns="" xmlns="http://www.w3.org/1999/xhtml">test</div>
  </body>
</html>

Patches

Pull Requests

History

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

non-namespace aware functions used
 [2004-12-15 18:48 UTC] swappp at yandex dot ru
Thanks.
But it is the simplified code.
Origianl:
$dom_html = DOMDocument::loadHTML('<div xmlns="http://www.w3.org/1999/xhtml">'.$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] chregu@php.net
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:

$div->setAttribute('xmlns','http://www.w3.org/1999/xhtml');

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 .

chregu
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 13:01:27 2024 UTC