如何调试lxml.etree.XSLTParseError:无效的表达式错误 [英] How to debug lxml.etree.XSLTParseError: Invalid expression error

查看:163
本文介绍了如何调试lxml.etree.XSLTParseError:无效的表达式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出为什么lxml无法解析XSL文档,该文档由具有各种xml:include的根"文档组成.我收到一个错误:

I'm trying to find out why lxml cannot parse an XSL document which consists of a "root" document with various xml:includes. I get an error:

Traceback (most recent call last):
File "s.py", line 10, in <module>
  xslt = ET.XSLT(ET.parse(d))
File "xslt.pxi", line 409, in lxml.etree.XSLT.__init__ (src/lxml/lxml.etree.c:151978)
lxml.etree.XSLTParseError: Invalid expression

这告诉我错误在lxml源代码中的什么位置,但是是否可以通过lxml获得更多关于错误在xsl中位置的信息,还是应该使用其他方法?我正在尝试提供接受XSL文档的服务,因此我无权访问XML编辑器进行手动调试.我想做的是提供有关为何转换失败的反馈.

That tells me where in the lxml source the error is, but is there a way to get more through lxml about where in the xsl the error is, or should I be using a different method? I'm trying to provide a service that accepts XSL documents, so I don't have access to an XML editor to debug manually. What I would like to do though is give feedback about why a transformation didn't succeed.

推荐答案

查看异常的属性,我看到它具有error_log,但是对于xpath错误(例如),日志仅包含有关位置的信息错误是在xpath内,因此它并不是特别有用.对于我描述的用例,有任意用户提交XSLT,但没有按钮式方法.取而代之的是,使用模式验证和自定义逻辑的组合来找出错误的原因以及为什么是错误,以便向用户报告,这可能是最简单的.

Looking at the exception's properties, I see that it has an error_log, but for an xpath error (for example) the log only includes information about where within the xpath the error is, so it's not especially helpful. For the use-case I describe, having arbitrary users submitting XSLT, there's not a push-button approach. Instead, it would be probably be easiest to use a combination of schema validation and custom logic to find out where the error is and why it's an error for the purpose of reporting back to the user.

这篇关于如何调试lxml.etree.XSLTParseError:无效的表达式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆