将 lxml XSLT Pretty_print 与 strip-space 结合起来

发布于 2024-08-15 03:27:51 字数 267 浏览 7 评论 0原文

我正在清理一些粗略的 XML,因此我在 XSL 转换的 lxml 输出上调用 etree.tostring() 时设置了 Pretty_print = True 。然而,这给我留下了原始输入中的一些垃圾空白节点,所以我添加了

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

……但这完全折叠了所有空白,忽略了漂亮的打印。有没有一种简单的方法可以使 strip-space 仅应用于输入,并且仍然让 lxml 应用漂亮的打印?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开半夏魅人心 2024-08-22 03:27:51

分两步做吗?首先去掉空格,然后漂亮地打印?

只是一个想法。

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

Just a thought.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文