Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • L libxslt
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 11
    • Issues 11
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 5
    • Merge requests 5
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • libxslt
  • Issues
  • #14
Closed
Open
Issue created Apr 06, 2019 by Ghost User@ghost

libxslt modifies the *input* document in place when stripping whitespace

xsltApplyStripSpaces() modifies the input document, meaning that subsequent usages of that document may result in different output. An XSLT transformation should never change the input document. This has also lead to crashes in lxml, but it looks like the original upstream bug report was lost: https://bugs.launchpad.net/lxml/+bug/583249

Here is an example using lxml:

from lxml import etree as et

transform = et.XSLT(et.fromstring('''\
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:strip-space elements="*"/>
  <xsl:template match="/">
    <foo><xsl:value-of select="a/b/text()" /></foo>
  </xsl:template>
</xsl:stylesheet>'''))

input_xml = et.fromstring('''\
<a>
    <b>huhu</b>
</a>
''')

print("INPUT BEFORE:")
print(et.tostring(input_xml, encoding='unicode'))
print("XSLT RESULT:")
print(transform(input_xml))
print("INPUT AFTER:")
print(et.tostring(input_xml, encoding='unicode'))

Output:

INPUT BEFORE:
<a>
    <b>huhu</b>
</a>
XSLT RESULT:
<?xml version="1.0"?>
<foo>huhu</foo>

INPUT AFTER:
<a><b>huhu</b></a>
Assignee
Assign to
Time tracking