我想使用XSLT将XML转换为XHTML。我想用Python来做,但我并不特别依赖任何库。继the directions here,我一直想这样的:XSLT与Python的lxml:禁止变量?
from lxml import etree
xslt_root=etree.parse('editions.xsl')
transform=etree.XSLT(xslt_root)
但我得到这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "xslt.pxi", line 406, in lxml.etree.XSLT.__init__ (src/lxml/lxml.etree.c:136874)
lxml.etree.XSLTParseError: Forbidden variable
我用this python script也尝试过,它采用的libxslt,但它给了我这些错误:
Forbidden variable
compilation error: file editions.xsl line 283 element key
xsl:key : 'match' pattern compilation failed '//tei:div/tei:ab/tei:ptr[@type='emendation'][@ana='#folger'] |// tei:rdg[contains(@wit,$rdg)]/tei:ptr[@type='emendation'][@ana='#folger']'
Forbidden variable
compilation error: file editions.xsl line 284 element key
xsl:key : 'match' pattern compilation failed '//tei:div/tei:ab/tei:ptr[@type='emendation'][@ana='#folger'] |// tei:rdg[contains(@wit,$rdg)]/tei:ptr[@type='emendation'][@ana='#folger']'
Forbidden variable
compilation error: file editions.xsl line 285 element key
xsl:key : 'match' pattern compilation failed '//tei:div/tei:ab/tei:ptr[@type='emendation'][@ana='#texta'] |// tei:rdg[contains(@wit,$rdg)]/tei:ptr[@type='emendation'][@ana='#texta']'
Forbidden variable
compilation error: file editions.xsl line 286 element key
xsl:key : 'match' pattern compilation failed '//tei:div/tei:ab/tei:ptr[@type='emendation'][@ana='#texta'] |// tei:rdg[contains(@wit,$rdg)]/tei:ptr[@type='emendation'][@ana='#texta']'
Forbidden variable
compilation error: file editions.xsl line 287 element key
xsl:key : 'match' pattern compilation failed '//tei:div/tei:ab/tei:ptr[@type='emendation'][@ana='#textb'] |// tei:rdg[contains(@wit,$rdg)]/tei:ptr[@type='emendation'][@ana='#textb']'
Forbidden variable
compilation error: file editions.xsl line 288 element key
xsl:key : 'match' pattern compilation failed '//tei:div/tei:ab/tei:ptr[@type='emendation'][@ana='#textb'] |// tei:rdg[contains(@wit,$rdg)]/tei:ptr[@type='emendation'][@ana='#textb']'
Traceback (most recent call last):
File "transform.py", line 21, in <module>
result = style.applyStylesheet(doc, None)
AttributeError: 'NoneType' object has no attribute 'applyStylesheet'
我正在使用的XSL文件是here。这是专业创建的,所以我不认为它会有很大的问题。
有没有办法来覆盖这个错误,以便我可以让我的XML文件转换为Python?或者有没有不同的方式来做这个XSLT,我不会一直得到错误?在浏览器(Firefox)中转换工作正常,但我无法让它在Python中工作。
你是怎么找到这个错误的?你知道一个有用的验证器吗? –
@MthethewWilcoxson:好的,我看着你的Python错误日志,说每行283到288有一个'禁止变量'的错误。然后我看着文件的第283行来找到禁止变量。这似乎是你应该需要的所有验证。 – Borodin
谢谢@Borodin,我没有注意到上面的错误输出,希望你使用了一些superduper验证器来找到它。 ;) –