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 587360 - xsl:attribute creates bogus namespaces for the reserved namespaces
xsl:attribute creates bogus namespaces for the reserved namespaces
Status: RESOLVED FIXED
Product: libxslt
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2009-06-29 20:22 UTC by Robin Upton
Modified: 2012-09-06 12:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed fix (5.73 KB, patch)
2012-09-05 17:23 UTC, Nick Wellnhofer
none Details | Review

Description Robin Upton 2009-06-29 20:22:32 UTC
<?php
//
// LibXML bug - <xsl:attribute> mishandles for the reserved namespaces:
//	http://www.w3.org/2000/xmlns/ & http://www.w3.org/XML/1998/namespace
//

$stylesheet= DOMDocument::loadXML('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/*">
		<xsl:copy>
			<!-- We cannot use AVT for xml:id, since the expression is not an NCName, so the stylesheet itself breaks the well-formed DOM rules. -->
			<!-- Hence, we try xsl:attribute, but this is poorly supported by a lot of XSL processors. -->
			<xsl:attribute name="id" namespace="http://www.w3.org/XML/1998/namespace">etc</xsl:attribute>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>');
$proc= new XSLTProcessor();
$proc->importStyleSheet($stylesheet);
$output= $proc->transformToDoc($stylesheet);
echo $output->saveXML();

?>
Comment 1 Robin Upton 2009-06-29 20:25:37 UTC
It creates a new namespace, which breaks the W3C spec. These 2 namespaces need to be caught and handled differently from the general case.
Comment 2 Robin Upton 2009-06-30 04:13:26 UTC
Some exploration has yielded a workaround for the cases in which the element is explicitly stated; adding a dummy attribute sets the namespace. e.g.

<fish xml:id="some-random-NCname">
   <xsl:attribute name="xml:id">etc</xsl:attribute>
</fish>

This still leaves unsolved the case when the element is generated dynamically, such as with <xsl:copy> above.
Comment 3 Daniel Veillard 2009-06-30 12:49:49 UTC
Just one early comment:

$output= $proc->transformToDoc($stylesheet);
echo $output->saveXML();

that's wrong, serialization of the output of the stylesheet should be done
in context of the stylesheet, but I have no idea how it's suposed to be done
from PHP.

I will look at the bug later though

Daniel
Comment 4 Nick Wellnhofer 2012-09-05 17:23:35 UTC
Created attachment 223568 [details] [review]
Proposed fix
Comment 5 Daniel Veillard 2012-09-06 12:49:35 UTC
Looks good, thanks Nick for fixing this !

http://git.gnome.org/browse/libxslt/commit/?id=f6c48211e5ee97b36ae9f3d2f8711fdce38e6e5e

Daniel