GNOME Bugzilla – Bug 698823
transforming an attribute while xml:space='preserve' causes a failure
Last modified: 2013-08-04 15:17:24 UTC
Tried this on notepad++ and Chrome, and failure happens each time. Works OK on other transformation engines. When setting xml:space='preserve', and then transforming an attribute, the transform fails. Here's some trivialest-possible demo code - I know that the xml:space attribute won't have any effect in these examples (because there is no text-only whitespace), but at the same time, I'd expect it to transform cleanly, and the transform fails. (No explanation, I'm afraid: Chrome shows a blank result, and Notepad++ reports that the transformation failed. This works: <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> This doesn't (says "Unable to apply transformation on current source"): <xsl:template match="@*|node()" xml:space='preserve'> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> This does: <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates select="node()" xml:space='preserve'/> </xsl:copy> </xsl:template> This doesn't: <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*" xml:space='preserve'/> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> Naturally, to exhibit this bug, the code that's being transformed needs to have some attributes. If there's no attributes, there's no failure. More commentary at http://stackoverflow.com/questions/16154092/xmlspace-preserve-doesnt-seem-to-get-on-with-xslapply-templates-select-nod
Your fourth example works for me with xsltproc and libxslt 1.1.28. The second example results in: runtime error: file bug698823.xsl line 4 element copy Attribute nodes must be added before any child nodes to an element. The reason is that there are whitespace text nodes between <xsl:template> and <xsl:apply-templates>. If they are preserved, they will be inserted before the attribute nodes which isn't allowed.