擅长:python、mysql、java
<p>我不确定它是否有用,但我不认为问题出在你的代码中。我认为问题是lxml不支持XSLT-2。在</p>
<p>您使用的模式需要符合2010 XSLT-2的ISO Schematron[1]。在</p>
<p>在氧气中打开模式并删除<code>querybinding=xslt2</code>属性会产生大量问题。这包括第553行的验证错误(<code><xsl:param name="num-cols" as="xs:integer"/></code>):“此元素上不允许属性”。这是lxml向[2]抛出解析错误的行。在</p>
<p>lxml没有实现XSTL-2,并且明确声明它只支持Schematron的“pure-XSLT-1.0<a href="http://schematron.com/implementation.html" rel="nofollow noreferrer">skeleton implementation</a>”(信息来自<a href="http://lxml.de/validation.html#id2" rel="nofollow noreferrer">http://lxml.de/validation.html#id2</a>)。在</p>
<p>如果你想让它和lxml一起工作,你可能会倒霉。据我所知,没有一个与XSLT-2兼容的pythonxml解析器(如果有人知道的话,那就太棒了)。在</p>
<p>这有点麻烦,但您可以使用子流程来使用外部工具(也许是crux+libsaxon)执行验证。这可能是唯一的解决办法。在</p>
<p>[1]链接模式的第35行:
<code>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
</code></p>
<p>[2]<code>lxml.etree.SchematronParseError: invalid schematron schema: <string>:553:0:ERROR:RELAXNGV:RELAXNG_ERR_EXTRACONTENT: Element function has extra content: param
</code></p>