Project

Profile

Help

Feature #5967

open

allow to set language version 4.0 for XPath evaluation

Added by Martin Honnen about 1 year ago. Updated 8 days ago.

Status:
In Progress
Priority:
Normal
Category:
C++ API
Start date:
2023-04-07
Due date:
% Done:

100%

Estimated time:
Found in version:
Fixed in version:
Platforms:

Description

SaxonJ EE supports setting the XPath language version to 4.0 (for the currently experimental XPath 4.0 support); it appears that SaxonC so far only allows that for XQuery (where a lang argument has been added to the API) but it so far lacks such an API for XPath evaluation.

It seems desirable to also allow pure XPath 4.0 evaluation with SaxonC.

Actions #1

Updated by O'Neil Delpratt about 1 year ago

  • Status changed from New to In Progress

Thanks for reporting this omission. Looking into it now.

Actions #2

Updated by O'Neil Delpratt about 1 year ago

The setLanguageVersion method is available on the XPathProcessor for the C++ and PHP APIs but is missing from the Python API.

Actions #3

Updated by O'Neil Delpratt about 1 year ago

As a workaround in Python API user can set the language as follows:

xpath_processor.set_property("lang:", "4.0")
Actions #4

Updated by O'Neil Delpratt about 1 year ago

  • Status changed from In Progress to Resolved

The set_language_version method has now been added to the PyXPathProcessor class. Available in the next maintenance release.

Actions #5

Updated by O'Neil Delpratt about 1 year ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in version set to 12.2

Bug fix applied in the SaxonC 12.2 maintenance release.

Actions #6

Updated by Martin Honnen 9 days ago

I find this is not working in SaxonC EE 12.4.2, code like

from saxoncee import PySaxonProcessor, PySaxonApiError

with PySaxonProcessor(license=True) as saxon_proc:
    print(saxon_proc.version)

    xpath_proc = saxon_proc.new_xpath_processor()

    xpath_proc.set_language_version('4.0')

    try:
        print(xpath_proc.evaluate('(1 to 5)=!>fn{. + .}()'))
    except PySaxonApiError as e:
        print(e)

    try:
        print(xpath_proc.evaluate('parse-html("<p>Test.<p>Test")'))
    except PySaxonApiError as e:
        print(e)

gives

SaxonC-EE 12.4.2 from Saxonica
XPST0003: The parser is not configured to allow use of XPath 4.0 syntax. Line number: -1
XPST0017: Cannot find a 1-argument function named Q{http://www.w3.org/2005/xpath-functions}parse-html(). Line number: -1

as does the workaround:

from saxoncee import PySaxonProcessor, PySaxonApiError

with PySaxonProcessor(license=True) as saxon_proc:
    print(saxon_proc.version)

    xpath_proc = saxon_proc.new_xpath_processor()

    xpath_proc.set_property('lang:', '4.0')

    try:
        print(xpath_proc.evaluate('(1 to 5)=!>fn{. + .}()'))
    except PySaxonApiError as e:
        print(e)

    try:
        print(xpath_proc.evaluate('parse-html("<p>Test.<p>Test")'))
    except PySaxonApiError as e:
        print(e)

I haven't been able to identify so far whether this is a regression or whether it never worked for the Python XPath API.

Actions #7

Updated by Martin Honnen 8 days ago

So looking at https://saxonica.plan.io/projects/saxonmirrorhe/repository/he/revisions/he_mirror_saxon_12_4_2/entry/src/main/java/net/sf/saxon/option/cpp/XPathProcessor.java#L417 which does

        if (parameterMap.containsKey("lang:")) {

and https://saxonica.plan.io/projects/saxonmirrorhe/repository/he/revisions/he_mirror_saxon_12_4_2/entry/src/main/java/net/sf/saxon/option/cpp/XPathProcessor.java#L418 which does

            valuei = (String) parameterMap.get("lang");

I wonder whether the second line should do

            valuei = (String) parameterMap.get("lang:");

instead?

Actions #8

Updated by O'Neil Delpratt 8 days ago

Yes that is the problem.

And because of comment #7 the following hack/workaround works for me:

    xpath_proc.set_property('lang:', '4.0')
    xpath_proc.set_property('lang', '4.0')
Actions #9

Updated by Martin Honnen 8 days ago

Oh, yes, that is smart thinking.

Nevertheless I hope you reopen this bug and fix it for the next maintenance release.

Actions #10

Updated by O'Neil Delpratt 8 days ago

  • Status changed from Closed to In Progress
  • Fixed in version deleted (12.2)

Reopening this bug issue.

Please register to edit this issue

Also available in: Atom PDF