GNOME Bugzilla – Bug 344183
xsl:copy misses to copy attributes in the XSLT namespace
Last modified: 2006-06-19 18:33:27 UTC
In xsltCopy() (transform.c) attributes in the XSLT are incorrectly not copied over to the result tree: if (!xmlStrEqual(attr->ns->href, XSLT_NAMESPACE)) { ret = xmlCopyProp(ctxt->insert, attr); ret->ns = xsltGetNamespace(ctxt, node, attr->ns, ctxt->insert); } The exclusion of attribute in the XSLT namespace applies only to attributes of literal result elements, not to any other attributes; e.g. not to attributes from the source tree. Example: Stylesheet ---------- <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="foo"> <xsl:copy> <xsl:apply-templates select="@*"/> </xsl:copy> </xsl:template> <xsl:template match="@*"> <xsl:copy/> </xsl:template> </xsl:stylesheet> Source doc ---------- <?xml version="1.0"?> <foo xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:bar="zoo"/> xsltproc's result ----------------- <?xml version="1.0"?> <foo/> Expected result --------------- <?xml version="1.0"?> <foo xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:bar="zoo"/> The implementation of xsl:copy-of seems to work OK - it copies over such attributes. Example: <xsl:template match="foo"> <xsl:copy> <xsl:copy-of select="@*"/> </xsl:copy> </xsl:template> This will copy the XSLT attributes as well.
Fixed in CVS HEAD. The current result: <?xml version="1.0"?> <foo xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:bar="zoo"/>