After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 518786 - xsl:copy of processing-instruction does not terminate correctly, produces invalid code
xsl:copy of processing-instruction does not terminate correctly, produces inv...
Status: RESOLVED NOTABUG
Product: libxslt
Classification: Platform
Component: general
1.1.21
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2008-02-26 08:10 UTC by edA-qa mort-ora-y
Modified: 2008-02-26 09:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
the PHP code which reproduces the problem (564 bytes, application/x-php)
2008-02-26 08:12 UTC, edA-qa mort-ora-y
Details

Description edA-qa mort-ora-y 2008-02-26 08:10:51 UTC
Matching a processing-instruction and copying the node does not produce the correct output: it will be terminated only with '>' rather than the expected '?>'

== Reproduction ==

This PHP example demonstrates the problem:

<?php

$xsld = new DOMDocument();
$xsld->loadXML( <<<EOT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1" indent="no" omit-xml-declaration="yes" media-type="text/html"/>
	<xsl:template match="processing-instruction()">
		<xsl:copy/>
	</xsl:template>
</xsl:stylesheet>

EOT
);

$xh = new XSLTProcessor();
$xh->importStyleSheet( $xsld );

$doc = new DOMDocument();
$doc->loadXML( <<<EOT
<?php some code ?>
<root></root>
EOT
);

echo $xh->transformToXML( $doc );

?>


== Workaround ==

The following workaround is available to handle specific processing instructions.

	<xsl:template match="processing-instruction('php')">
		<xsl:text disable-output-escaping="yes">&lt;?php </xsl:text>
		<xsl:value-of select="." disable-output-escaping='yes'/>
		<xsl:text disable-output-escaping="yes">?></xsl:text>
	</xsl:template>
Comment 1 edA-qa mort-ora-y 2008-02-26 08:12:20 UTC
Created attachment 105962 [details]
the PHP code which reproduces the problem
Comment 2 Daniel Veillard 2008-02-26 08:43:30 UTC
Nope, libxslt behaviour is correct.
You parse the XML as XML. In XML PIs are terminated by ?> so
the content of the PI does not include the ? character
When you serialize back as HTML, in HTML the PIs are just
terminated by > so libxml2 serializer does not output a ?

So either output as XML (<xsl:output method="xml")
or add the ? in the XSLT.

  No bug here,

Daniel
Comment 3 edA-qa mort-ora-y 2008-02-26 09:35:53 UTC
Okay, understood.  Switching to XML output does what I intended.