Project

Profile

Help

repeatedly calling run_query_to_string seems to return the result of the first call

Added by Martin Honnen almost 5 years ago

Using Saxon HEC 1.2.1 I wrote the following sample Python program:

import saxonc

with saxonc.PySaxonProcessor() as proc:
    print(proc.version)

    xml = '''<root>
      <items>
         <item>foo</item>
         <item>bar</item>
      </items>
    </root>'''
    
    input_xml = proc.parse_xml(xml_text = xml)
    
    print(input_xml)
    
    xquery_processor = proc.new_xquery_processor()
    
    xquery_processor.set_context(xdm_item = input_xml)
    
    for query in ['.', 'count(//*)', '(1 to 10) ! ("Example " || .)']:
    
        print(xquery_processor.run_query_to_string(query_text = query))

The output I get is

Saxon/C 1.2.1 running with Saxon-HE 9.9.1.5C from Saxonica
<root>
   <items>
      <item>foo</item>
      <item>bar</item>
   </items>
</root>
<root>
   <items>
      <item>foo</item>
      <item>bar</item>
   </items>
</root>

<root>
   <items>
      <item>foo</item>
      <item>bar</item>
   </items>
</root>

<root>
   <items>
      <item>foo</item>
      <item>bar</item>
   </items>
</root>

so it seems the first query is executed three times or the second and third query execution return the result of the first execution.

Is that meant to work that way? Do I have to reset the processor somehow?

Creating a new PyXQueryProcessor for each call works:

    for query in ['.', 'count(//*)', '(1 to 10) ! ("Example " || .)']:
    
        xquery_processor = proc.new_xquery_processor()
    
        xquery_processor.set_context(xdm_item = input_xml)
    
        print(xquery_processor.run_query_to_string(query_text = query))

Replies (1)

RE: repeatedly calling run_query_to_string seems to return the result of the first call - Added by O'Neil Delpratt almost 5 years ago

This is a bug. I have created the following bug issue: https://saxonica.plan.io/issues/4386

I will get a fix out ASAP.

A workaround would be to call clearProperties() before updating new values.

The following should work:

    xquery_processor = proc.new_xquery_processor()

    for query in ['.', 'count(//*)', '(1 to 10) ! ("Example " || .)']:

        xquery_processor.set_context(xdm_item = input_xml)

        print(xquery_processor.run_query_to_string(query_text = query))

        xquery_processor.clear_properties()
    (1-1/1)

    Please register to reply