Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • L libxslt
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 14
    • Issues 14
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Terraform modules
    • Model experiments
  • 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

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