I'm trying to transform XML to XHTML using XSLT. I'd like to do it using Python, but I'm not particularly attached to any library. Following the directions here, I've been trying this:
from lxml import etree
xslt_root=etree.parse('editions.xsl')
transform=etree.XSLT(xslt_root)
But I get this error:
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
I also tried using this python script, which uses libxslt, but it gives me these errors:
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'
The XSL file I'm using is here. It's professionally created, so I wouldn't think there would be big problems with it.
Is there a way to override this error, so that I can get my XML file to transform in python? Or is there a different way to do this XSLT where I won't be getting errors all the time? Transforming in the browser (Firefox) works fine, but I can't get it to work in Python.