php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29623 XSLTProcessor don't process 'omit-xml-declaration' in 'xsl:output'
Submitted: 2004-08-12 02:28 UTC Modified: 2004-08-12 08:25 UTC
From: x-penguin at tut dot by Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5CVS-2004-08-12 (dev) OS: Linux
Private report: No CVE-ID: None
 [2004-08-12 02:28 UTC] x-penguin at tut dot by
Description:
------------
PHP Version 5.1.0-dev, configure with:
'./configure' '--prefix=/usr/' '--with-apxs2' '--with-gettext'
'--with-iconv' '--with-mysql' '--enable-mbstring=ru' '--enable-mbregex'
'--enable-mbstr-enc-trans' '--disable-short-tags' '--with-xsl'
'--with-libxml' '--without-sqlite' '--enable-soap'

libxslt Version     1.1.8
libxml Version      2.6.11
libexslt Version    1.1.8

apache 2.0.48

XSLTProcessor don't process 'omit-xml-declaration' in 'xsl:output'. If 'omit-xml-declaration' set to 'yes' than xml declaration will be output; when set to 'no', than xml declaration will be output too.


Reproduce code:
---------------
<?php
$xsl = new DomDocument();
$xsl->loadXML(
'<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
<xsl:output method="xml" omit-xml-declaration="no"/>
<xsl:template match="/">
    <xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>'
);

$xml = new DomDocument;
$xml->loadXML('<?xml version="1.0"?><null>test</null>');

$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);

$dom = $proc->transformToDoc($xml);
echo $dom->saveXML();
?>

Expected result:
----------------
test

Actual result:
--------------
<?xml version="1.0"?>
test

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-12 08:25 UTC] chregu@php.net
transformToDoc always looses special XSLT formatting options (like omit-xml-declaration, indent, method, etc), because the returned Document is a simple DomDocument with no such information.

Use

$string = $proc->transformToXml($xml);
print $string;

to achieve what you want


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 20:01:29 2024 UTC