Project

Profile

Help

Bug #5446

closed

transform_to_file on PyXslt30Processor and PyXsltExecutable ignores documented xdm_node keyword argument

Added by Martin Honnen over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Category:
Python
Start date:
2022-04-04
Due date:
% Done:

100%

Estimated time:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Found in version:
11.3
Fixed in version:
11.4
SaxonC Languages:
SaxonC Platforms:
SaxonC Architecture:

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.

Please register to edit this issue

Also available in: Atom PDF