php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53050 processing instructions won't append correctly
Submitted: 2010-10-13 02:25 UTC Modified: 2010-10-13 10:35 UTC
From: jameswithers89 at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.14 OS: Linux
Private report: No CVE-ID: None
 [2010-10-13 02:25 UTC] jameswithers89 at gmail dot com
Description:
------------
In order to make my XHTML compatible with Internet Explorer it is recommended (http://www.w3.org/MarkUp/2004/xhtml-faq#ie) to have <?xml-stylesheet type="text/xsl" href="copy.xsl"?> as a processing instruction. However, trying to append this does not work as expected.


Test script:
---------------
	$Implementation = new DOMImplementation();
	$Doctype = $Implementation->createDocumentType("html");
	$Document = $Implementation->createDocument("http://www.w3.org/1999/xhtml", "html", $Doctype);
	// Workaround for IE XHTML issues: http://www.w3.org/MarkUp/2004/xhtml-faq#ie
	$IeXhtml = $Document->createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"copy.xsl\"");
	$Document->documentElement->insertBefore($IeXhtml);
	$Head = $Document->createElement("head");
	$Title = $Document->createElement("title", "My page");
	$Head->appendChild($Title);
	$Document->documentElement->appendChild($Head);
	$Body = $Document->createElement("body");
	$Script = $Document->createElement("script", "");
	$Script->setAttribute("src", "test.js"); 
	$Script->setAttribute("type", "text/javascript");
	$Body->appendChild($Script);
	$Document->documentElement->appendChild($Body);
	echo $Document->saveXML();

Expected result:
----------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="copy.xsl"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My page</title>
</head>
<body>
<script src=test.js" type="text/javascript"></script>
</body>
</html>


Actual result:
--------------
<?xml version="1.0"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<?xml-stylesheet type="text/xsl" href="copy.xsl"?>
<head>
<title>My page</title>
</head>
<body>
<script src=test.js" type="text/javascript"></script>
</body>
</html>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-13 10:35 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-10-13 10:35 UTC] aharvey@php.net
This works fine; you just have to call insertBefore with the right reference node. In this case, replacing:

	$Document->documentElement->insertBefore($IeXhtml);

with:

	$Document->insertBefore($IeXhtml, $Document->doctype);

will take care of that.

Not a bug -> closing.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 08:01:23 2020 UTC