Bug #5287
closedHow to use XPath system function from Python with SaxonC 11.1
100%
Description
I am trying to figure a way how to use and call an XPath function from Python with Saxon 11.1. The Python API shows a function get_system_function
at https://www.saxonica.com/saxon-c/doc11/html/saxonc.html#PyXdmFunctionItem without showing the possible arguments. It is also not clear whether it is supposed to be static (as the correspondent C++ method seems to be) or an instance method.
I have tried to call it/access it directly as PyXdmFunctionItem.get_system_function
, but that fails with "TypeError: descriptor 'get_system_function' for 'saxonc.PyXdmFunctionItem' objects doesn't apply to a 'saxonc.PySaxonProcessor' object"; trying to call it as PyXdmFunctionItem().get_system_function
fails in the Cython code:
from saxonc import *
with PySaxonProcessor(license=True) as proc:
print("Test SaxonC on Python")
print(proc.version)
parse_json = PyXdmFunctionItem().get_system_function(proc, '{http://www.w3.org/2005/xpath-functions}parse-json', 1)
xdmItem = parse_json.call(proc, [proc.make_string_value('[1,2,3]')])
gives
Traceback (most recent call last):
File "C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\saxonc-11.1-python\json-processing\parse-json-test1.py", line 7, in <module>
parse_json = PyXdmFunctionItem().get_system_function(proc, '{http://www.w3.org/2005/xpath-functions}parse-json', 1)
File "saxonc.pyx", line 3968, in saxonc.PyXdmFunctionItem.get_system_function
c_func = self.derivedfptr.getSystemFunction(proc.thisptr, name, arity)
TypeError: expected bytes, str found
Updated by O'Neil Delpratt almost 3 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 100
- Found in version set to 11.1
Thanks for reporting this issue. The problem was we failed to convert the python string for the argument name
to C string.
Bug fixed and available for the next maintenance release.
Updated by Debbie Lockett almost 3 years ago
- Tracker changed from Support to Bug
- Status changed from Resolved to Closed
- Fixed in version set to 11.2
Bug fix applied in the Saxon 11.2 maintenance release.
Please register to edit this issue