views:

221

answers:

1

I'm cleaning up some gross XML, and so I've had pretty_print = True set in the call to etree.tostring() on my lxml output of the XSL transform. However, that left me with a few junk whitespace nodes from the original input, so I added

<xsl:strip-space elements="*"/>

...but that completely collapses all whitespace, ignoring pretty print. Is there an easy way to make strip-space just apply to the input, and still get lxml to apply pretty print?

+1  A: 

Do it in two steps? First strip the spaces, then pretty-print?

Just a thought.

hcayless
I'm not manually working with the element tree or the XML string, I'm just using lxml's XSLT transform functionality
UltraNurd
Yeah, all I'm saying is do two transforms. Is this a one-time cleanup, or something you need to make repeatable? If it's a one-time thing then doing two transforms shouldn't be a problem.
hcayless