Project

Profile

Help

SaxonC 11.99 on Windows: using file paths with Windows separator backslash doesn't seem to work, need to use forwards slash

Added by Martin Honnen over 1 year ago

Using SaxonC 11.4 (using HE) under Windows using Windows like file paths with a backslash works fine for me e.g. the code below using Schxslt 1.9.4 and some Schematron schema and some sample XML gives me an SVRL report output.

With SaxonC 11.99 (also using HE) under Windows it seems all those paths don't work, I don't get any error output from my attempts to check for exception_occurred but the first attempt to compile_stylesheet doesn't seem to have returned anything as the line trying to use compiled_schema = compiled_schxslt.apply_templates_returning_string(source_file = sample_schematron) gives an error AttributeError: 'NoneType' object has no attribute 'apply_templates_returning_string.

Interestingly enough if I change all my file paths to use a forwards slash in the paths as the separator (e.g.

schxslt_dir = r'C:/Users/marti/OneDrive/Documents/schematron/schxslt-1.9.4/2.0'
schxslt_xslt = 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'

) the code runs fine with SaxonC 11.99.

Is that a known and intended change or limitation for SaxonC 12 (11.99) under Windows that file paths need to use a forwards slash / as the separator?

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'

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)

    compiled_schxslt = proc.new_xslt30_processor().compile_stylesheet(stylesheet_file = schxslt_dir + '\\' + schxslt_xslt)

    if proc.exception_occurred:
        print(proc.error_message)

    compiled_schema = compiled_schxslt.apply_templates_returning_string(source_file = sample_schematron)

    if proc.exception_occurred:
        print(proc.error_message)

    compiled_schema = proc.new_xslt30_processor().compile_stylesheet(stylesheet_text = compiled_schema)

    if proc.exception_occurred:
        print(proc.error_message)

    svrl_report = compiled_schema.apply_templates_returning_string(source_file = sample_xml)

    print(svrl_report)

Replies (3)

Please register to reply

RE: SaxonC 11.99 on Windows: using file paths with Windows separator backslash doesn't seem to work, need to use forwards slash - Added by O'Neil Delpratt over 1 year ago

SaxonC 12 now uses the XML resolver under the hood to manage resolving of filenames. This is bug in SaxonC because the XML resolver is expecting URIs, but SaxonC is passing a string with "", which isn't allowed in URIs.

I have created the following bug issue to keep track of its progress: #5789

RE: SaxonC 11.99 on Windows: using file paths with Windows separator backslash doesn't seem to work, need to use forwards slash - Added by O'Neil Delpratt over 1 year ago

I suspect that the exception has occurred on the PyXslt30Processor. Therefore the PySaxonProcessor does not know about the exception. This is a subtle change from SaxonC 11 to 12 that will need documenting.

The following code:

    compiled_schxslt = proc.new_xslt30_processor().compile_stylesheet(stylesheet_file = schxslt_dir + '\\' + schxslt_xslt)

    if proc.exception_occurred:
        print(proc.error_message)

Needs change to something like the following:

    xslt30_proc = proc.new_xslt30_processor()
    compiled_schxslt = xslt30_proc.compile_stylesheet(stylesheet_file = schxslt_dir + '\\' + schxslt_xslt)

    if xslt30_proc.exception_occurred:
        print(xslt30_proc.error_message)

RE: SaxonC 11.99 on Windows: using file paths with Windows separator backslash doesn't seem to work, need to use forwards slash - Added by O'Neil Delpratt over 1 year ago

With that change in the exception handling I am getting the the following error message from the resolver:

Exception from catalog resolver resolverURI()
    (1-3/3)

    Please register to reply