Project

Profile

Help

Support #4847

sotransformToString - Python

Added by David Zabala 5 months ago. Updated 5 months ago.

Status:
In Progress
Priority:
Normal
Category:
C++ API
Start date:
2020-12-02
Due date:
% Done:

0%

Estimated time:
Found in version:
1.2.1

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

Xslt30Processor.cpp (62.1 KB) Xslt30Processor.cpp O'Neil Delpratt, 2020-12-03 11:27

Related issues

Has duplicate Saxon/C - Bug #4859: Jet Runtime Has detected Unrecoverable Error-libsaxonhec.dll transformToString not foundAwaitingInfo2020-12-17

<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>

History

#1 Updated by O'Neil Delpratt 5 months ago

  • Project changed from Saxon to Saxon/C
  • 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

#2 Updated by O'Neil Delpratt 5 months ago

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.

#3 Updated by O'Neil Delpratt 5 months ago

  • Status changed from New to AwaitingInfo

#4 Updated by David Zabala 5 months ago

It works perfectly now, thank you very much!

#5 Updated by O'Neil Delpratt 5 months ago

  • Status changed from AwaitingInfo to In Progress

Bug fixed and committed to repository in the redesign. Unit tests required

#6 Updated by O'Neil Delpratt 4 months ago

  • Has duplicate Bug #4859: Jet Runtime Has detected Unrecoverable Error-libsaxonhec.dll transformToString not found added

Please register to edit this issue

Also available in: Atom PDF