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 698823 - transforming an attribute while xml:space='preserve' causes a failure
transforming an attribute while xml:space='preserve' causes a failure
Status: RESOLVED NOTABUG
Product: libxslt
Classification: Platform
Component: general
unspecified
Other All
: Normal major
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2013-04-25 10:37 UTC by Jules May
Modified: 2013-08-04 15:17 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jules May 2013-04-25 10:37:01 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
Comment 1 Nick Wellnhofer 2013-08-04 15:17:24 UTC
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.