|  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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: tenkei at mailinator dot com
New email:
PHP Version: OS:


 [2009-04-17 21:17 UTC] tenkei at mailinator dot com
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="">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" doctype-system="" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />
    <xsl:template match="/Test">
                <title>Test Page</title>
            <body>This is a test.</body>

[ 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" "">
<html xmlns="">
        <title>Test Page</title>
    <body>This is a test.</body>

Actual result:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns=""><head><title>Test Page</title></head><body>This is a test.</body></html>


Add a Patch

Pull Requests

Add a Pull Request


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

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-2021 The PHP Group
All rights reserved.
Last updated: Sun Apr 11 09:01:24 2021 UTC