php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48009 XSLTProcessor::transformToDoc output missing linebreaks
Submitted: 2009-04-17 21:17 UTC Modified: 2009-04-20 13:47 UTC
From: tenkei at mailinator dot com Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.2.9 OS: Linux
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: tenkei at mailinator dot com
New email:
PHP Version: OS:

 

 [2009-04-17 21:17 UTC] tenkei at mailinator dot com
Description:
------------
An XSLTProcessor object imports a stylesheet that will output XML using the XHTML1 strict doctype system, then has its transformToDoc() method called on a DOMElement object.  The DOMDocument object returned by the method will not produce XML with linebreaks or indentation when saveXML() is called.

Reproduce code:
---------------
[ XSL ]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />
    <xsl:template match="/Test">
        <html>
            <head>
                <title>Test Page</title>
            </head>
            <body>This is a test.</body>
        </html>
    </xsl:template>
</xsl:stylesheet>

[ XML ]
<Test />

[ PHP ]
$proc = new XSLTProcessor();
$xslt = new DOMDocument();
$xslt->load( 'transform.xsl' );
$proc->importStylesheet( $xslt );
$xml = new DOMDocument();
$xml->load( 'file.xml' );
$doc = $proc->transformToDoc( $xml );
print $doc->saveXML();

Expected result:
----------------
<?xml version="1.0"?>
<!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">
    <head>
        <title>Test Page</title>
    </head>
    <body>This is a test.</body>
</html>

Actual result:
--------------
<?xml version="1.0"?>
<!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"><head><title>Test Page</title></head><body>This is a test.</body></html>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-20 13:47 UTC] iliaa@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

If you want the output XML to be formatted nicely (by default output is 
compact) you need to do $doc->formatOutput = true; before calling 
SaveXML() method.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC