Actions
Bug #5849
closedtransform_to_file() in PyXslt30Processor not working.
Start date:
2023-01-23
Due date:
% Done:
100%
Estimated time:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Found in version:
12.0
Fixed in version:
12.1
SaxonC Languages:
SaxonC Platforms:
SaxonC Architecture:
Description
Using Saxon 12 (installed w/pypi) on Python 3.8.
transform_to_file()
seems to try to use the output file as input.
If I try the following python without an existing output file "simple_output.xml":
from saxonche import *
def run():
with PySaxonProcessor(license=False) as proc:
print(f"Processor version: {proc.version}")
xsltproc = proc.new_xslt30_processor()
xsltproc.transform_to_file(source_file=r"try_saxon_input.xml",
stylesheet_file=r"simple.xsl",
output_file=r"simple_output.xml")
for x in range(0, 3):
run()
I get the following console output (I get this 3 times, but only including once for brevity. Also, I'm running this in PyCharm.):
Processor version: SaxonC-HE 12.0 from Saxonica
Error
I/O error reported by XML parser processing simple_output.xml. Caused by
java.io.FileNotFoundException: C:\Users\Dan Haley\Desktop\try_saxon\simple_output.xml (The
system cannot find the file specified)
If I create a file named "simple_output.xml" with the content <foo/>
, I don't get an exception but this is what "simple_output.xml" looks like:
<foo processed="1 2 3"/>
So it appears it's using the output as input.
Here's my XSLT if needed to reproduce:
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" expand-text="yes">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/*">
<xsl:copy>
<xsl:attribute name="processed" select="let $tokens := tokenize(@processed)
return string-join(($tokens,count($tokens)+1),' ')"/>
<xsl:apply-templates select="@* except @processed|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
As a work-around, I'm first compiling the stylesheet and using the transform_to_file()
method from PyXsltExecutable.
Files
Please register to edit this issue
Actions