GNOME Bugzilla – Bug 313711
namespace collision with namespace-alias
Last modified: 2021-07-05 11:00:39 UTC
I'm trying to write a sort of generative XSLT: an XSLT stylesheet which creates another XSLT stylesheet. Unfortunately, I've confused xsltproc. The simplest example if the following. I copy content of "xsl:stylesheet" as is and add a dummy template. [code] <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" xmlns:axsl = "http://www.w3.org/1999/XSL/TransformAlias" version = "1.0"> <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> <xsl:template match="xsl:stylesheet"> <xsl:copy> <xsl:copy-of select="node()|@*"/> <axsl:template match="none"/> </xsl:copy> </xsl:template> </xsl:stylesheet> [/code] Note that "xsl:copy-of" and "axsl:template" are in different namespaces. Now apply this stylesheet to itself. Result is the following. [code] <?xml version="1.0"?> <axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <axsl:namespace-alias xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" stylesheet-prefix="axsl" result-prefix="xsl"/> <axsl:template xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" match="xsl:stylesheet"> <axsl:copy> <axsl:copy-of select="node()|@*"/> <axsl:template match="none"/> </axsl:copy> </axsl:template> <axsl:template match="none"/></axsl:stylesheet> [/code] Now "axsl:copy-of" and "axml:template" are in the same namespace. It is incorrect. By the way: 1) I expected that output prefix should be "xsl", not "axsl" (despite the specification doesn't require it). 2) Here is output from Saxon: [code] <?xml version="1.0" encoding="utf-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" version="1.0"> <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> <xsl:template match="xsl:stylesheet"> <xsl:copy> <xsl:copy-of select="node()|@*"/> <axsl:template match="none"/> </xsl:copy> </xsl:template> <axsl:template xmlns:axsl="http://www.w3.org/1999/XSL/Transform" match="none"/></xsl:stylesheet> [/code]
True, the current result is incorrect. The XSLT 1.0 spec does not define which prefix to use for the resulting namespace binding. For XSLT 2.0 this is defined: the result-prefix is used, if in-scope for both the xsl:namespace-alias and the literal result element (see bug #341325). The problem is anchored in xsltGetNamespace() (namespaces.c), which will apply namespace aliases. We get this effect if copying from the source tree: xsltCopyTree() --> xsltGetNamespace() xsltCopyPropList() --> xsltGetNamespace() Namespace aliases are only intended for literal result elements - not for source trees. So we need to remove the ns-aliasing in all functions, which are intended to be used on non literal result elements.
Output of Saxon 8.1.1: --------------------- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"> <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> <xsl:template match="xsl:stylesheet"> <xsl:copy> <xsl:copy-of select="node()|@*"/> <axsl:template match="none"/> </xsl:copy> </xsl:template> <xsl:template match="none"/></xsl:stylesheet> Apparently earlier versions of Saxon, missed to change the prefix of the last generated "template" element. Result of Libxslt with the refactored code: ------------------------------------------- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" version="1.0"> <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> <xsl:template match="xsl:stylesheet"> <xsl:copy> <xsl:copy-of select="node()|@*"/> <axsl:template match="none"/> </xsl:copy> </xsl:template> <xsl:template match="none"/></xsl:stylesheet>
Mark this bug as fixed when we switch to the refactored code paths.
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxslt/-/issues/ Thank you for your understanding and your help.