Project

Profile

Help

Bug #4853

proc.transform_to_string causes python to crash

Added by Brian Higashide 10 months ago. Updated 10 months ago.

Status:
In Progress
Priority:
High
Category:
Python
Start date:
2020-12-07
Due date:
% Done:

0%

Estimated time:
Found in version:
Saxon HE 1.2.1
Fixed in version:

Description

I am trying to use the xslt processor to validate schematron.

import saxonc
proc=saxonc.PyXslt30Processor(license=False)
proc.transform_to_string(source_file=path_to_file)

Running this code causes python to crash. There's no traceback or error feedback, it just crashes.

sample.sch (1.13 KB) sample.sch Brian Higashide, 2020-12-07 17:57

History

#1 Updated by Michael Kay 10 months ago

  • Category set to Python
  • Assignee set to O'Neil Delpratt

#2 Updated by O'Neil Delpratt 10 months ago

Hi,

If you on the linux platform, you can try running the python file with gdb, which should show up what is causing the crash. For example:

gdb python3 example.py

> handle SIG35 noprint nostop
> run example.py
> bt

As an alternative is it possible to for you to supply the stylesheet please?

#3 Updated by Brian Higashide 10 months ago

I can't upload the file I was using originally, but I have created a new .sch file from a code snippet and I am seeing the same behavior here.

#4 Updated by O'Neil Delpratt 10 months ago

Thanks. I need a complete repo please. Where do I find the XSLT stylesheet that you use for the schematron file? Maybe you can email it to us.

#5 Updated by O'Neil Delpratt 10 months ago

  • Status changed from New to AwaitingInfo

Update:

Following some offline correspondence the issue is the same as #4701. The explain in that bug issue should help here:

"The way Schematron validation typically works is that you run a (schematron-supplied) XSLT transformation that 
takes your schematron rules as input and produces an XSLT stylesheet as output, and then you run this XSLT 
stylesheet against your source document. As far as Saxon is concerned, both processes are simply regular 
XSLT transformations, that can be run using the standard XSLT transformation API."

Also see: https://saxonica.plan.io/issues/4701#note-6

#6 Updated by O'Neil Delpratt 10 months ago

  • Status changed from AwaitingInfo to In Progress

Attempting to compile an invalid stylesheet should not crash python. The above python code is actually incorrect.

The PyXslt30Processor object needs to be created via the PySaxonProcessor object (which is the context). See the example code below:

      with saxonc.PySaxonProcessor(license=False) as proc:
         xslt30proc = proc.new_xslt30_processor()
         ...

#7 Updated by O'Neil Delpratt 10 months ago

  • Status changed from In Progress to AwaitingInfo

#8 Updated by Martin Honnen 10 months ago

As for using the Saxon-C Python API to compile a Schematron schema file first to XSLT to then run the XSLT representation of the Schematron file in a second call with Saxon-C see the code samples in https://stackoverflow.com/questions/65134343/schematron-validation-with-python-and-xslt-2-0. There is a link to the Schxslt implementation of Schematron which is now the current and supported XSLT based Schematron implementation.

#9 Updated by O'Neil Delpratt 10 months ago

Thank you Martin for providing a solution.

#10 Updated by Brian Higashide 10 months ago

Thank you this is helpful. I was also able to use Oxygen XML to generate a stylesheet.

I am seeing a different problem now, When I run this line:

-with saxonc.PySaxonProcessor(license=False) as proc:-

I am getting the following error

Unable to load C:\Program Files\Saxonica\SaxonHEC1.2.1\libsaxonhec.dll

The .dll file does exist in that location.

#11 Updated by O'Neil Delpratt 10 months ago

It looks like a classpath issue. Did you follow the instructions for Windows platform here: https://www.saxonica.com/saxon-c/documentation/index.html#!starting/installingpython

#12 Updated by O'Neil Delpratt 10 months ago

Are you running a 32-bit or 64-bit Windows build? Saxon/C only runs on 64-bit Windows. We have stopped support for the 32-bit version.

#13 Updated by Brian Higashide 10 months ago

I am running 64-bit, Saxon was installed to default directory and added to PYTHONPATH environment variable, but I am still getting the same error.

#14 Updated by O'Neil Delpratt 10 months ago

  • Status changed from AwaitingInfo to In Progress

Thanks for the information. These kind of problems are somethings difficult to reproduce. Please can you describe your setup in more detail, such as, how you are invoking Saxon/C (is from Powershell, command or something else?), Windows version, etc.

#15 Updated by O'Neil Delpratt 10 months ago

Your error may also be similar to the issue #4436 where the problem turned out to be a 32-bit python installed on 64-bit Windows.

#16 Updated by Brian Higashide 10 months ago

Yes, the issue was my python version was 32 bit. After installing the 64 bit version I am now able to run the code without issue.

Thanks!

Please register to edit this issue

Also available in: Atom PDF