Search code examples
pythonxquerysaxonsaxon-c

How to use the collection()-function with saxonche


I am trying to use the collection()-function using the new saxonche-Python-Module (https://pypi.org/project/saxonche/).

I would expect, that it returns all XML-documents inside the current directory. Instead it just returns None.

My code looks like:

from saxonche import PySaxonProcessor
from os import getcwd

with PySaxonProcessor(license=False) as proc:
    print(proc.version)
    xq = proc.new_xquery_processor()
    xq.set_query_base_uri(getcwd())
    xq.set_query_content("collection('.')/node()")
    r = xq.run_query_to_value()
    print(r)

Any suggestions?


Solution

  • I get the suggested collection('?select=*.xml') to work if I use e.g.

    from pathlib import Path
    

    and then set

    xq.set_query_base_uri(Path('.', 'foo.xml').absolute().as_uri())