GNOME Bugzilla – Bug 587360
xsl:attribute creates bogus namespaces for the reserved namespaces
Last modified: 2012-09-06 12:49:35 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(); ?>
It creates a new namespace, which breaks the W3C spec. These 2 namespaces need to be caught and handled differently from the general case.
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.
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
Created attachment 223568 [details] [review] Proposed fix
Looks good, thanks Nick for fixing this ! http://git.gnome.org/browse/libxslt/commit/?id=f6c48211e5ee97b36ae9f3d2f8711fdce38e6e5e Daniel