Project

Profile

Help

Support #4701

Python bindings for schematron validation

Added by Martijn Hemeryck 25 days ago. Updated 7 days ago.

Status:
Closed
Priority:
Low
Category:
Python
Start date:
2020-09-01
Due date:
% Done:

0%

Estimated time:
Found in version:
1.2.1

Description

For our purposes, we need to do a schematron-based validation -- which I know is supported in your JAVA API (using https://www.saxonica.com/documentation/index.html#!javadoc/net.sf.saxon.s9api/XsltTransformer@transform). I was wondering whether this is also supported in the python version and whether you'd have a simple example to demonstrate this -- I couldn't figure it out from https://www.saxonica.com/saxon-c/doc/html/saxonc.html

Note that I'm also just using the HE / open source version, maybe you only support it with the licensed version?

History

#1 Updated by O'Neil Delpratt 24 days ago

  • Category set to Python
  • Status changed from New to AwaitingInfo
  • Assignee set to O'Neil Delpratt
  • Found in version set to 1.2.1

Hi Martijn,

We have had users of Saxon/C successfully do schematron-based validation in the past. Unfortunately we have no specific examples with schematron stylesheet within Saxon/C APIs but they should work fine in the same way as the examples given with the python API.

See examples on general transform: http://www.saxonica.com/saxon-c/documentation/index.html#!samples/samples_python There are many more examples in the Saxon.C.API/python-saxon directory too.

If you need more assistance please let us know.

#2 Updated by Martijn Hemeryck 24 days ago

Hi, thanks for the quick feedback!

I already looked into the accompanying or sample code that you mentioned. Since you mention "schematron stylesheet", does that mean I should just use the PyXslt30Processor or PyXsltProcessor (not sure which one) with the schematron as a stylesheet? I did try that, and got the response that it wasn't a valid stylesheet.

When using the PySchemaValidator I immediately got the response that this was not supported in the unlicensed version.

#3 Updated by O'Neil Delpratt 24 days ago

The PyXslt30Processor API is designed for XSLT 3.0. Therefore I suggesting using that API.

The PySchemaValidator API is for XML Schema Definition (XSD) validation which requires EE license, therefore for schematron validation you would not require this API.

#4 Updated by Michael Kay 24 days ago

Martin, 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.

#5 Updated by Martijn Hemeryck 24 days ago

OK, then there's probably some issue in the way that I'm trying to use the schematrons.

Small snippet:


import saxonc

src = "<source_file>.xml"
sch = "<schematron_file>.sch"


with saxonc.PySaxonProcessor(license=False) as proc:
    xsltproc = proc.new_xslt30_processor()
    result = xsltproc.transform_to_string(source_file=src, stylesheet_file=sch)
    print(result)

this gets me as output:

Static error at schema on line 5 column 111 of <schematron_file>.sch:
  XTSE0150: The supplied file does not appear to be a stylesheet
None

So, in principle this should work, but you think there's an issue with the schematron structure itself?

#6 Updated by Michael Kay 24 days ago

Note that we don't provide support for third-party applications built on top of Saxon, and that includes Schematron.

You might find the diagram in the article at https://www.xml.com/pub/a/2003/11/12/schematron.html useful to explain the Schematron processing model. (Scroll down 60% of the page)

You need to do two transformations: the first takes the schematron schema (.sch) as its source document (not as its stylesheet!) and produces as output a stylesheet, which is used to perform the second transformation.

#7 Updated by O'Neil Delpratt 7 days ago

  • Status changed from AwaitingInfo to Closed

I am closing this issue as I don't believe there is an associated bug but it is a usability issue with the Saxon/C API to do schematron validation. Feel free to open it again if you can produce a sample which shows a problem within the product.

Please register to edit this issue

Also available in: Atom PDF