Forums » Saxon/C Help and Discussions »
How to compile .xsl to .sef with SaxonC EE for target HE with Python API
Added by Martin Honnen almost 2 years ago
I would like to test whether an SEF compiled XSLT 3 stylesheet performs better with SaxonC 12 HE than the .xsl version.
So after some tests and some Slack exchange with O'Neil the conclusion is that SaxonC 12/11.99 EE is needed to compile for Saxon 12/11.99.
Currently I only have access to the Python wheel of SaxonC 12/11.99 EE, I run my .xsl through compile_stylesheet
with save=True
and an output_file
set and get an SEF, but on trying to execute it with HE I get an error Cannot load expression with tag gcEE. The stylesheet uses Saxon-EE features
.
So that raises the question: how to use the Python API to compile with EE for target HE?
Replies (5)
Please register to reply
RE: How to compile .xsl to .sef with SaxonC EE for target HE with Python API - Added by O'Neil Delpratt almost 2 years ago
Is it possible you can supply a repo?
RE: How to compile .xsl to .sef with SaxonC EE for target HE with Python API - Added by Martin Honnen almost 2 years ago
Well, yes, but it is a general question on how to set the target can set with the command line API for SEF compilation with the Python API.
What I did to compile with 11.99 EE and which creates the SEF is
from saxonc import *
# schxslt_dir = r'C:\Users\marti\OneDrive\Documents\schematron\schxslt-1.9.4\2.0'
# schxslt_xslt = r'pipeline-for-svrl.xsl.SaxonEE114Compiled.sef' #r'pipeline-for-svrl.xsl'
# these are the fixed Windows forwards slash paths to work around other issue
schxslt_dir = r'C:/Users/marti/OneDrive/Documents/schematron/schxslt-1.9.4/2.0'
schxslt_xslt = r'pipeline-for-svrl.xsl.SaxonEE114Compiled.sef'
with PySaxonProcessor(license=True) as proc:
print(proc.version)
proc.set_cwd(schxslt_dir)
proc.set_configuration_property('http://saxon.sf.net/feature/licenseFileLocation', r'C:\Program Files\Saxonica\saxon-license.lic')
xslt30_processor = proc.new_xslt30_processor()
xslt30_processor.compile_stylesheet(stylesheet_file = 'pipeline-for-svrl.xsl', save = True, output_file = 'pipeline-for-svrl.xsl.SaxonEE124Compiled.sef')
if xslt30_processor.exception_occurred:
print("Schxslt compilation failed", xslt30_processor.error_message)
The code I run with HE 11.99 then uses the code below and fails on the attempt to execute the compiled SEF schxslt with "Schxslt compilation failed Cannot load expression with tag gcEE. The stylesheet uses Saxon-EE features".
I don't think the issue is with a particular stylesheet but if it matters the Schxslt schxslt-1.9.4 directory content is from unzipping https://github.com/schxslt/schxslt/releases/download/v1.9.4/schxslt-1.9.4-xslt-only.zip.
But the issue I think is a general, compilation from the command line has a target
option I can set to e.g. HE
or JS
but seems to default to EE
, how can I set the target from the Python API, if that is possible at all?
from saxonc import *
# schxslt_dir = r'C:\Users\marti\OneDrive\Documents\schematron\schxslt-1.9.4\2.0'
# schxslt_xslt = r'pipeline-for-svrl.xsl.SaxonEE114Compiled.sef' #r'pipeline-for-svrl.xsl'
#
# sample_xml = r'C:\Users\marti\OneDrive\Documents\schematron\streaming\examples\BookPrice\books.xml'
# sample_schematron = r'C:\Users\marti\OneDrive\Documents\schematron\streaming\examples\BookPrice\price.sch'
schxslt_dir = r'C:/Users/marti/OneDrive/Documents/schematron/schxslt-1.9.4/2.0'
schxslt_xslt = r'pipeline-for-svrl.xsl.SaxonEE124Compiled.sef' #r'pipeline-for-svrl.xsl.SaxonEE114Compiled.sef' #r'pipeline-for-svrl.xsl'
sample_xml = r'C:/Users/marti/OneDrive/Documents/schematron/streaming/examples/BookPrice/books.xml'
sample_schematron = r'C:/Users/marti/OneDrive/Documents/schematron/streaming/examples/BookPrice/price.sch'
with PySaxonProcessor(license=False) as proc:
print(proc.version)
xslt30_processor = proc.new_xslt30_processor()
compiled_schxslt = xslt30_processor.compile_stylesheet(stylesheet_file = schxslt_dir + '/' + schxslt_xslt)
if xslt30_processor.exception_occurred:
print("Schxslt compilation failed", xslt30_processor.error_message)
else:
compiled_schema = compiled_schxslt.apply_templates_returning_value(source_file = sample_schematron)
if compiled_schxslt.exception_occurred:
print("Compiling Schematron failed", compiled_schxslt.error_message)
else:
xslt30_processor = proc.new_xslt30_processor()
compiled_schema = xslt30_processor.compile_stylesheet(stylesheet_node = compiled_schema.head)
if xslt30_processor.exception_occurred:
print(xslt30_processor.error_message)
else:
svrl_report = compiled_schema.apply_templates_returning_string(source_file = sample_xml)
print(svrl_report)
RE: How to compile .xsl to .sef with SaxonC EE for target HE with Python API - Added by Martin Honnen almost 2 years ago
The Java API probably has https://www.saxonica.com/html/documentation11/javadoc/net/sf/saxon/s9api/XsltCompiler.html#setTargetEdition-java.lang.String- to set the target for compilation, perhaps the SaxonC API needs something similar.
RE: How to compile .xsl to .sef with SaxonC EE for target HE with Python API - Added by O'Neil Delpratt almost 2 years ago
Yes the SaxonC API needs something like this. Creating a bug issue for this.
RE: How to compile .xsl to .sef with SaxonC EE for target HE with Python API - Added by O'Neil Delpratt almost 2 years ago
Bug issue #5791 created.
Please register to reply