Closed alexis-via closed 6 years ago
Hi. Are you sure its an infinite loop and that it simply doesnt take forever? It sometimes takes up to 30 minutes to generate the XSLT from the SCH files!!!
30 minutes !!! No, I didn't wait that long... I'm running it again now, let's see if it works if I wait long enough.
You are right, I had to wait longer ! After 20 minutes, it fails:
Traceback (most recent call last):
File "./fx-schematron.py", line 10, in <module>
schematron = isoschematron.Schematron(sct_root, store_report=True)
File "/usr/local/lib/python2.7/dist-packages/lxml/isoschematron/__init__.py", line 285, in __init__
validator_xslt = self._compile(schematron, **compile_params)
File "src/lxml/xslt.pxi", line 600, in lxml.etree.XSLT.__call__
lxml.etree.XSLTApplyError: Fail: This implementation of ISO Schematron does not work with
schemas using the "xslt2" query language.
Does your library have a way to use precompiled XSLTs? That would simplify your life - right?
According to this post https://stackoverflow.com/questions/46767903/schematronparseerror-invalid-schematron-schema-for-isosts-schema there is no implementation of schematron in Python that support queryBinding="xslt2". So I guess we can close this bug report... as it seems there is no solution to this problem in Python :-(
Sorry :(
@phax Do you mean that this xslt file here https://github.com/CenPC434/validation/blob/master/cii/xslt/EN16931-CII-validation.xslt is a pre-compiled version of the CII schematron, so that I could use this XSLT file directly ?
When I try to use the XSLT file provided in this git report "cii/xslt/EN16931-CII-validation.xslt", it fails on line 2129:
Traceback (most recent call last):
File "./fx-xslt.py", line 14, in <module>
transform = etree.XSLT(xslt_root)
File "src/lxml/xslt.pxi", line 410, in lxml.etree.XSLT.__init__
lxml.etree.XSLTParseError: xsl:when : could not compile test expression '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:SpecifiedTaxRegistration/ram:ID[@schemeID = ('VAT', 'FC')] or /rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTaxRepresentativeTradeParty/ram:SpecifiedTaxRegistration/ram:ID[@schemeID = 'VAT']'
The small Python script I used for that is the following:
#! /usr/bin/python
from lxml import etree
xslt_file = open('/home/alexis/new_boite/dev/schematron-fx/cii/xslt/EN16931-CII-validation.xslt', 'r')
xslt_root = etree.parse(xslt_file)
print "xslt_root=", xslt_root
f = open('/home/alexis/tmp/factur-x-demov7.xml', 'r')
fx_xml_root = etree.parse(f)
print "fx_xml_root=", fx_xml_root
transform = etree.XSLT(xslt_root)
print "transform=", transform
newdom = transform(fx_xml_root)
print "newdom=", newdom
print etree.tostring(newdom, pretty_print=True)
Python doesn't support XSLT2 by default. However you can invoke external XSLT2 engine like Saxon. Or perhaps someone already created Python wrapper around Saxon/C. See http://www.saxonica.com/saxon-c/index.xml
@alexis-via Yes, that was the idea. The XSLT you mention is a pre-compiled version of the Schematron. Because what usually happens is the following:
SCH
is converted via a predefined XSLT
to the SCH-XSLT
(in reality its 3 conversions but who cares)SCH-XSLT
can than be applied as any other XSLT onto the XML
to be validated, creating an SVRL
outputSVRL
to determine the success/failure status.Any updates on a means to validate xslt2, either through lxml or other?
I'm trying to use the CII or UBL schematron from Python lxml's lib, but I always get an infinite loop.
Here is a scenario to reproduce the bug:
Then I run the following python script:
I get an infinite loop when reaching isoschematron.Schematron(). I also have an infinite loop with the UBL schematron.
I don't know if the bug is caused by the schematron or if it's in python's lxml lib. So I also reported a bug to lxml: https://bugs.launchpad.net/lxml/+bug/1783890
And you get an infinite loop when you reach the line isoschematron.Schematron().