php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44279 transformToXml does not properly close tags when stylesheet output is xml
Submitted: 2008-02-28 01:06 UTC Modified: 2008-02-28 07:49 UTC
From: phpbugs at xmlnode dot com Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.2.5 OS: Debian 2.6 stable
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phpbugs at xmlnode dot com
New email:
PHP Version: OS:

 

 [2008-02-28 01:06 UTC] phpbugs at xmlnode dot com
Description:
------------
It's pretty basic,  I have an xsl stylesheet with an output method of 
xml and an encoding of iso-8859-1 (which doesn't matter) using xhtml11 
as the doctype, but the same is seen for other xhtml doctypes. When I 
call transformToXML I get tags like this:

<hr> <br> <link ...>

when I call transformToURI() I get the proper tags <hr/> <br /> <link 
/>, etc.  If I call transformToDoc() and then use saveXML() I still 
see the open tags <hr> <br> <link ...>, but if I call transformToDoc 
and then save() the tags are correct.  I would have thought it was a 
browser-specific issue, but I've tried every browser available to me 
(7 total across multiple platforms)  My guess is that internally save 
and transformToURI; which work, call the same method, but that 
transformToXML and saveXML which don't work call the same somewhat 
broken method.

Reproduce code:
---------------
stylesheet (condensed):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" media-type="text/html" doctype-public="-//W3C//DTD XHTML 1.1 //EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd" omit-xml-declaration="yes" encoding="iso-8859-1"/>
<xsl:template match="/"><html xml:lang="en">		<head><title>whatever</title></head><body><br/><hr/><img src='somesource'/></body></html></xsl:template>

$xml = new DOMDocument('1.0');
$xml->loadXML('<PAGE/>');

$xsl = new DOMDocument('1.0);
$xsl->load(<path to stylesheet>);  // you'll need to set this

$proc = new XsltProcessor();
$proc->importStylesheet($xsl);
echo $proc->transformToDoc($xml);



Expected result:
----------------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 //EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
<html 
xml:lang="en"><head><title>whatever</title></head><body><br/><hr/><img 
src="somesource"/></body></html>

I should note that this is the output from either transformToURI($xml, 
<path>) or $dom = transformToDOC($xml); $dom->save(<path>);  In fact if 
you want you can just change $dom->save(path) to $dom->saveXML() and 
you'll get completely different results.




Actual result:
--------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 //EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
<?xml version="1.0" encoding="iso-8859-1"?><html xml:lang="en">
<head><title>whatever</title></head>
<body>
<br><hr>
<img src="somesource">
</body>
</html>

You'll notice that not only are the tags not closed the XML 
declaration is in a different spot.  

I assume you'll ask, because I know I would, but I'm running the 
absolute latest libxml2 (2.6.31) and libxsl (1.1.22), compiled 
everything last night (2/26/2008) saw the behavior before upgrading

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-28 06:13 UTC] chregu@php.net
If I run your code on a commandline PHP it does work correctly:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 //EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
<html 
xml:lang="en"><head><title>whatever</title></head><body><br/><hr/><img 
src="somesource"/></body></html>

I assume, the conversion from <br/> to <br> happens somewhere else in 
your case, either the browser or apache. try something like wget to 
get the raw source of your output.

My experience with the xslt extension also tells me, that this can0t 
be PHPs fault, I never saw something like that. Also your experience 
with the difference between saveXML and save tells me, that the 
conversion happens somewhere else.
 [2008-02-28 07:49 UTC] phpbugs at xmlnode dot com
Ugh. you're right.  Another developer had an output handler that does a 
bunch of decently important stuff, but in there was a buzz-killing 
saveHTML().  Please consider this redacted - "the office" - season 2 :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 13:01:27 2024 UTC