Bug #5446
closedtransform_to_file on PyXslt30Processor and PyXsltExecutable ignores documented xdm_node keyword argument
100%
Description
https://www.saxonica.com/saxon-c/doc11/html/saxonc.html#PyXslt30Processor-transform_to_file documents a keyword argument xdm_node (PyXdmNode)
, as does https://www.saxonica.com/saxon-c/doc11/html/saxonc.html#PyXsltExecutable-transform_to_file.
However, the source code for those function does not make any attempt to use/process that xdm_node
argument, it simply does e.g.
def transform_to_file(self, **kwds):
"""
transform_to_file(self, **kwds)
Execute transformation to a file. It is possible to specify the as an argument or using the set_output_file method.
Args:
**kwds: Possible optional arguments: source_file (str) or xdm_node (PyXdmNode). Other allowed argument: stylesheet_file (str), output_file (str)
and base_output_uri (str) which is used for for resolving relative URIs in the href attribute of the
xsl:result-document instruction.
Example:
1) xsltproc.transform_to_file(source_file="cat.xml", stylesheet_file="test1.xsl", output_file="result.xml")
2) xsltproc.set_source("cat.xml")\r
xsltproc.setoutput_file("result.xml")\r
xsltproc.transform_to_file(stylesheet_file="test1.xsl")
3) node = saxon_proc.parse_xml(xml_text="<in/>")\r
xsltproc.transform_to_file(output_file="result.xml", stylesheet_file="test1.xsl", xdm_node= node)
"""
cdef char * c_sourcefile = NULL
cdef char * c_outputfile = NULL
cdef char * c_base_output_uri = NULL
cdef char * c_stylesheet = NULL
cdef PyXdmNode node_ = None
for key, value in kwds.items():
if isinstance(value, str):
if key == "source_file":
c_sourcefile = make_c_str(value)
elif key == "base_output_uri":
'''c_base_output_uri = make_c_str(value)'''
py_string_string = value.encode('utf-8') if value is not None else None
c_base_output_uri = py_string_string if value is not None else ""
self.thisxptr.setBaseOutputURI(c_base_output_uri)
elif key == "output_file":
'''c_outputfile = make_c_str(value)'''
py_string_string = value.encode('utf-8') if value is not None else None
c_outputfile = py_string_string if value is not None else ""
elif key == "stylesheet_file":
'''c_stylesheet = make_c_str(value)'''
py_string_string = value.encode('utf-8') if value is not None else None
c_stylesheet = py_string_string if value is not None else ""
self.thisxptr.transformFileToFile(c_sourcefile, c_stylesheet, c_outputfile)
That way, when trying to use transform_to_file(xdm_node = someNode ...)
with Python, nothing happens, I don't get any error but obviously never any result as there is no input being processed.
The C++ API has a transformToFile
method taking an XdmNode doing something like
void XsltExecutable::transformToFile(XdmNode *source) {
if (source != nullptr) {
//source->incrementRefCount();
parameters["node"] = source;
}
transformFileToFile(nullptr, nullptr);
}
I am not sure how to integrate that from the Python side, not sure whether the Python code needs to call transformToFile or set that node
parameter.
I guess other transform_to...
methods taking an xdm_node
are also affected, having looked through all of them, apply_templates_returning_file
seems to be able to use the xdm_node
argument, however, although it has it easier as it can set e.g. setInitialMatchSelection
to that node.
Updated by O'Neil Delpratt over 2 years ago
Thanks for reporting this issue. There is clearly a bug in the transform_to_file
method for PyXsltExecutable class and possibly in the PyXslt30Processor class too.
Updated by O'Neil Delpratt over 2 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 100
- Found in version set to 11.3
Two fixed have been applied for this bug issue:
-
Documentation fix for
transform_to_file
in thePyXslt30Processor
class. Thexdm_node
keyword argument should not be there and has been dropped. Transforms on thePyXslt30Processor
have been simplified to 'oneshot' methods with file name arguments. -
The
transform_to_file
method in thePyXsltExecutable
class now accepts thexdm_node
keyword argument. This was an oversight.
Updated by O'Neil Delpratt over 2 years ago
Fix also applied in PyXsltExecutable.transform_to_value
Updated by O'Neil Delpratt over 2 years ago
- Status changed from Resolved to Closed
- Fixed in version set to 11.4
Bug fix applied in the SaxonC 11.4 maintenance release.
Updated by Martin Honnen over 2 years ago
The documentation https://www.saxonica.com/saxon-c/doc11/html/saxonc.html#PyXslt30Processor-transform_to_file doesn't seem to have been (completely) fixed to no longer show the xdmNode
argument of transform_to_file
, as there is a complete example
3) node = saxon_proc.parse_xml(xml_text="<in/>")
xsltproc.transform_to_file(output_file="result.xml", stylesheet_file="test1.xsl", xdm_node= node)
still in it. Confusing.
Updated by O'Neil Delpratt over 2 years ago
Thanks Martin. I have applied the fix to the documentation, which will be updated to the live site shortly.
Please register to edit this issue