Bug #4847
closedsotransformToString - Python
0%
Description
I am trying to get the xls messages (xsl:message) using the following code:
xsltproc = proc.new_xslt30_processor()
outputi = xsltproc.transform_to_string(source_file="source.xml", stylesheet_file="style.xsl")
print(outputi) #This Works
msg = xsltproc.get_xsl_messages()
And I get the following error:
/usr/lib/libsaxonhec.sotransformToString not found
Files
Related issues
Updated by O'Neil Delpratt almost 4 years ago
- Project changed from Saxon to SaxonC
- Category changed from User error to Python Build
- Assignee set to O'Neil Delpratt
- Priority changed from Low to Normal
- Found in version set to 1.2.1
Thanks for reporting this issue. It looks like a bug in the JNI. Investigating it now
Updated by O'Neil Delpratt almost 4 years ago
- File Xslt30Processor.cpp Xslt30Processor.cpp added
- Category changed from Python Build to C++ API
I managed to reproduce the error message and it is bug.
The problem is the return type used in the internal JNI method signature in the C++ code is wrong. The bug has been fixed in a redesign of the xsl:message mechanism to make it more usable. This will be available in the next release, but as I workaround see below.
In the method getXslMessage
of the class file Xslt30Processor.cpp
we currently have the following:
jmethodID mID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
"getXslMessages",
"()[Lnet/sf/saxon/s9api/XdmValue;");
Please replace it with the following:
jmethodID mID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
"getXslMessages",
"()[Lnet/sf/saxon/s9api/XdmNode;");
I have also attached the file to this bug with the patch so you can just drop and replace the file if that is easier. Then rebuild the Saxon/C python extension again.
What actually happens to the xsl:messages by default is to output messages to the standard output console, but this does not find its way to python. As mentioned in the bug issue #4147 to capture the messages you will have to call xsltproc.set_property('m', '')
before you do the transformation. See example python code below which should work for you:
xsltproc = proc.new_xslt30_processor()
xsltproc.set_property('m', '') #This flag creates a Message Listener which intercepts the messages to return `PyXdmNode` objects of the messages
outputi = xsltproc.transform_to_string(source_file="source.xml", stylesheet_file="style.xsl")
print(outputi) #This Works
messages = xsltproc.get_xsl_messages()
if messages is not None:
i = 0
while i < messages.size:
print(messages.item_at(i))
i += 1
The get_xsl_message
returns an PyXdmValue
of the individual messages which are PyXdmNode
objects.
The PyXdmValue should be iterable. I will create another bug issue for this.
Updated by O'Neil Delpratt almost 4 years ago
- Status changed from New to AwaitingInfo
Updated by David Zabala almost 4 years ago
It works perfectly now, thank you very much!
Updated by O'Neil Delpratt almost 4 years ago
- Status changed from AwaitingInfo to In Progress
Bug fixed and committed to repository in the redesign. Unit tests required
Updated by O'Neil Delpratt almost 4 years ago
- Has duplicate Bug #4859: Jet Runtime Has detected Unrecoverable Error-libsaxonhec.dll transformToString not found added
Updated by O'Neil Delpratt almost 3 years ago
- Status changed from In Progress to Resolved
Bug fixed in SaxonC 11
Updated by O'Neil Delpratt almost 3 years ago
- Tracker changed from Support to Bug
- Status changed from Resolved to Closed
- Fixed in version set to 11.1
Bug fix available in the SaxonC 11.1 release
Please register to edit this issue