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>