Bug #6143
closedWhite space in file path causing an error
100%
Description
Hi,
I was using Saxonche version 12.0.0 and was able to perform the following without any issue in Python:
fileout = os.path.join(folder,define)
proc_define = PySaxonProcessor(license=False) xsltproc_define = proc_define.new_xslt30_processor() executable = xsltproc_define.compile_stylesheet(stylesheet_file=xls2xml_stylesheet) node = proc_define.parse_xml(xml_text=file_xml) executable.transform_to_file(output_file=fileout, xdm_node= node)
Variable fileout is a file path that contains 1 or more white spaces (i.e. C:/Users/OneDrive - XXX/Documents/test.xml)
It used to work just fine with 12.0.0 but since I upgraded to 12.3.0, I get the following error:
saxonche.PySaxonApiError: Illegal character in path at index xx: C:/Users/OneDrive - XXX/Documents/test.xml
It seems the "transform_to_file" no longer accepts output_file parameter value with white spaces.
Updated by Martin Honnen over 1 year ago
I think you will have more success in current SaxonC versions if you use URIs; in Python I find that pathlib/Path has functions absolute()
and as_uri()
so you can do e.g.
from pathlib import Path
from saxonche import PySaxonProcessor
xslt1 = '''<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates/>
<xsl:comment expand-text="yes">Run with {system-property('xsl:product-name')} at {current-dateTime()}</xsl:comment>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
'''
with PySaxonProcessor(license=False) as saxon:
output_uri = Path(r'C:\Users\Marti\OneDrive\Documents\saxonc test folder', 'result1.xml').absolute().as_uri()
print(output_uri)
xslt30_processor = saxon.new_xslt30_processor()
xslt30_executable = xslt30_processor.compile_stylesheet(stylesheet_text=xslt1)
xslt30_executable.transform_to_file(xdm_node=saxon.parse_xml(xml_text='<root/>'),output_file=output_uri)
and then SaxonC 12.3 correctly writes the result to file:///C:/Users/Marti/OneDrive/Documents/saxonc%20test%20folder/result1.xml which means a file result1.xml
is created in e.g. C:\Users\marti\OneDrive\Documents\saxonc test folder
Updated by O'Neil Delpratt over 1 year ago
Thanks Martin for the workaround. Yes doing the escaping to %20 in the python will work as a workaround.
Internally we now use the XML resolver to do the resolving which takes a URI. We convert file names to URI, it looks like the the whitespaces are not being escaped to %20. I will make improvements to do the escaping internally.
Updated by Pierre Dostie over 1 year ago
Thank you Martin, I implemented your workaround and it works now.
Updated by O'Neil Delpratt over 1 year ago
- Category set to Python API
- Assignee set to O'Neil Delpratt
Updated by O'Neil Delpratt over 1 year ago
- Status changed from New to Resolved
- % Done changed from 0 to 100
I have applied an internal patch to fixed the whitespace issue with file names.
Also patched the use of file://
as the base_uri as the cwd in SaxonProcessor now successfully resolves in the execution of a stylesheet.
Updated by O'Neil Delpratt about 1 year ago
- Status changed from Resolved to Closed
- Fixed in version set to 12.4
Bug fix applied in the SaxonC 12.4 Maintenance release
Please register to edit this issue