Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fn:transform #4386

Merged
merged 72 commits into from Aug 14, 2022
Merged

Commits on Aug 3, 2022

  1. Copy the full SHA
    54b3037 View commit details
    Browse the repository at this point in the history
  2. [ignore] Code cleanup

    adamretter authored and alanpaxton committed Aug 3, 2022
    Copy the full SHA
    640cf41 View commit details
    Browse the repository at this point in the history

Commits on Aug 4, 2022

  1. [feature] fn-transform - first functionality

    Set up some unit tests from equivalent XQTS tests.
    Wrap document returned in a map, per spec.
    Serialize output when requested, borrowing eXist serialization code.
    Use of stylesheet-params option working
    Rename unit tests to .xqm
    Improve transform option type error checking
    Make badly typed options throw XPTY0004 (type error XPath exception) instead of throwing directly from Java.
    Handle some of fn:transform “initial-template” param
    
    This is part of what is termed call-template invocation, and the transformer’s callTemplate() method is used.
    
    Reject call on non-existent source-node
    Add getStringValue() and toString() to XQueryContext for help in debugging
    Try harder to resolve stylesheet URIs (in retrospect probably not right yet).
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    c4b2d31 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    e773003 View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    b36a2e9 View commit details
    Browse the repository at this point in the history
  4. fn:transform - use DocUtils to get stylesheet

    and fix up the primary output key in the case where it should not be “output”
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    3c880a9 View commit details
    Browse the repository at this point in the history
  5. fn:transform - get xsl:version from simplified stylesheet

    XQTS test fn-transform
    <test-case name="fn-transform-7b">
    
    Uses a stylesheet of the form:
    
    <out xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xsl:version='2.0'>
                              <xsl:value-of select='.' />
                             </out>
    
    and we were not picking the stylesheet version from that. Burrow through the element and check for the appropriate NamespaceNode and xsl:version.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    2e71b6c View commit details
    Browse the repository at this point in the history
  6. fn:transform - base URI for transformation

    To set the base URI, we need to set the system id for the stylesheet. Then the stylesheet can resolve-uri successfully, and write secondary output documents.
    
    Add a result document handler to collect the output for secondary output documents.
    
    Result documents now returned to us and we can build tha map with URI and value.
    
    Test runner passing document URI where that exists, and we set it up as the system id to the Saxon transformer if it does exist.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    340e878 View commit details
    Browse the repository at this point in the history
  7. fn:transform - refactor options, handle raw output

    Separate Options class within FnTransform where fully resolved values of options are fetched from the options map once. Called as the first step of eval(), and leaves doing evaluation work based on the options as a cleanly separated task.
    
    Raw output request is now handled, and rejected (pre XSLT 3.0) or produced (3.0+) per the spec.
    
    Handling raw output and checking for the raw option mutliple times was the indication that we needed to factor out the options processing.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    edeb1b7 View commit details
    Browse the repository at this point in the history
  8. Copy the full SHA
    564fd66 View commit details
    Browse the repository at this point in the history
  9. Copy the full SHA
    94d8bfa View commit details
    Browse the repository at this point in the history
  10. fn:transform - Fix multiple document output

    All documents were going to the same builder.
    Each individual result was consequently the union of all documents.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    713e39d View commit details
    Browse the repository at this point in the history
  11. add initial-function param to fn:transform

    And a beginning implementation thereof.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    9558366 View commit details
    Browse the repository at this point in the history
  12. fn:transform - remove wrong “raw” < 3.0

    Erroneously prohibited RAW delivery-format in XSLT version < 3.0
    Misreading of the specs
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    38f209b View commit details
    Browse the repository at this point in the history
  13. fn:transform - Handle some XdmValue conversions

    Implement some conversion in the {@link Convert} class. The saxDestination conversion loses type information in some cases, e.g. fn-transform-63 from XQTS has a <xsl:template name='main' as='xs:integer’>. which alongside "delivery-format":"raw" fails to deliver an int.
    
    We implement a vestigial Convert class to use the XdmValue generated by the alternative form of call to the transformer with a template, in this case.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    f00c0e7 View commit details
    Browse the repository at this point in the history
  14. fn:transform - transformer parameters

    Parse and pass template-params to transformer.
    Parse and pass tunnel-params to transformer, in the same way as template-params.
    
    static-params
    
    Implement in same way as other param sets.
    
    Add a test for serialization-params.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    f5c3561 View commit details
    Browse the repository at this point in the history
  15. fn:transform - initial- mode template conflict

    initial-mode and initial-template are conflicting parameters.
    Create UTs for this conflict.
    Throw an exception when both are supplied.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    12df629 View commit details
    Browse the repository at this point in the history
  16. fn:transform - parameter conflict

    source_node and initial_match_selection conflict
    Return an error if both are supplied.
    
    Re-instate raw output of document.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    a6210b4 View commit details
    Browse the repository at this point in the history
  17. fn:transform - attempt at initial-match-selection

    refactor options so we have ItemOption where the supplied option must be an item.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    fdb0772 View commit details
    Browse the repository at this point in the history
  18. fn:transform - sequence conversion Saxon to eXist

    We need to create a “raw” eXist object from the “raw” Saxon transformation result when delivery-format is “raw”. Add more conversion code to do this for sequences.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    1dba2da View commit details
    Browse the repository at this point in the history
  19. Copy the full SHA
    71186f9 View commit details
    Browse the repository at this point in the history
  20. fn:transform - initial-match-selection as document

    initial-match-selection can be a document
    add more unit tests in this area
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    91d9239 View commit details
    Browse the repository at this point in the history
  21. fn:transform - base-output-uri param type

    Accept a string as this is often what is provided in practice.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    dd6b0a7 View commit details
    Browse the repository at this point in the history
  22. fn:transform - string URI convertibility

    Several XQTS tests start passing when we do these:
    
    A string is a valid base-output-uri for fn:transform
    A URI is a valid string subtype
    
    To predict a later change, a URI should not in general be a valid string subtype, and we will recant this idea, but it works for XQTS tests. The correct non-impactful solution will be to special case allowing and converting a URI when we expect a string in parameters to fn:transform.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    05c5ae8 View commit details
    Browse the repository at this point in the history
  23. fn:transform - add initial-mode test (failing)

    Start to TDD initial-mode.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    6ec173e View commit details
    Browse the repository at this point in the history
  24. fn:transform - refactor template invocation flow

    Create a sepate invocation object with methods which
    directly reflect the concept of invocation mode/type that is used in the spec.
    
    call-template, call-function and apply-template modes each have their own methods, one of which is selected on invocation of the template according to the options that have been supplied.
    
    https://www.w3.org/TR/xpath-functions-31/#func-transform
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    17f1bad View commit details
    Browse the repository at this point in the history
  25. fn:transform - pass initial-mode parameter

    initial-mode parameter was not being passed to the invoked transformer.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    b0882ff View commit details
    Browse the repository at this point in the history
  26. fn:transform - global-context-item parameter

    Implement support for global-context-item parameter
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    f09aa19 View commit details
    Browse the repository at this point in the history
  27. fn:transform - type of base output uri

    Allow this to be supplied as an AnyURIValue or as a StringValue, as both get supplied in practice.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    ac9d1fb View commit details
    Browse the repository at this point in the history
  28. Copy the full SHA
    c075a6a View commit details
    Browse the repository at this point in the history
  29. fn:transform - exactly one source of stylesheet

    The parameters stylesheet-location, stylesheet-node, and stylesheet-text cannot occur together.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    214f467 View commit details
    Browse the repository at this point in the history
  30. fn:transform - source-node may not be a document

    Extract the owning document if this is the case
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    944d4bc View commit details
    Browse the repository at this point in the history
  31. fn:transform - stylesheet-params ignored

    Use the values supplied in stylesheet-params.
    Was previously using a mock testing value.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    b082606 View commit details
    Browse the repository at this point in the history
  32. Copy the full SHA
    345ef6d View commit details
    Browse the repository at this point in the history
  33. fn:transform - resolve base URI in stylesheet-text

    While still retaining a correct checksum.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    0c313a1 View commit details
    Browse the repository at this point in the history
  34. fn:transform - refactor, pull out compilation step

    Compile the stylesheet as a separate function prior to use.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    7df6f5f View commit details
    Browse the repository at this point in the history
  35. Copy the full SHA
    7bf576c View commit details
    Browse the repository at this point in the history
  36. Copy the full SHA
    d22ccf0 View commit details
    Browse the repository at this point in the history
  37. fn:transform - resolvedStylesheetBaseURI optional

    Make the parameter an Optional<>. It makes the intention of testing absence/presence more obvious.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    d5d0e3f View commit details
    Browse the repository at this point in the history
  38. [bugfix] fn:transform - correct URI error codes

    Some resolver cases manage to pick up a base URI for stylesheet-text when they shouldn’t make that assumption. They then fail to open a non-existent (wrongly generated) filename, and finally return the wrong error.
    
    Now, we check for this case in the URI resolver and force the correct error immediately.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    ac9fc2a View commit details
    Browse the repository at this point in the history
  39. [bugfix] fn:transform initial-function param

    fn:transform call with initial-function specified must also supply function-params. Check this.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    f091597 View commit details
    Browse the repository at this point in the history
  40. [bugfix] fn:transform - relative stylesheet

    Handle location of stylesheet which is specified as a relative URL.
    We appeared to only be handling absolute locations of stylesheets, per test fn-transform-25. Also remove some code which didn’t make sense and didn’t appear to be used.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    e222e3b View commit details
    Browse the repository at this point in the history
  41. [bugfix] fn:transform - global-context-item

    Support code for converting a node as part of a document to Saxon was wrong. It was always returning the converted document containing the node.
    
    Now count out the “index position” of the original node in all the layers of the document (e.g. 3rd child of 5th child of root) and use that index position to yield the corresponding node in the converted document. Of course, the converted document has the same structure, so the index position works.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    c7008d9 View commit details
    Browse the repository at this point in the history
  42. [testsuite] fn:transform - fn-transform-82e UT

    Prepare a correct unit test for the XQTS test fn-transform-82e
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    7d94522 View commit details
    Browse the repository at this point in the history
  43. [testsuite] fn:transform - repair UTs

    Up to this point we have created a number of fn:transform UTs that have been used as stepping stones to pass XQTS tests. Some have been left in a non-working state.
    
    Triage for the UTs that can be made to work without too much effort, and remove the rest. This leaves us with a handy set of working UTs.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    706a52f View commit details
    Browse the repository at this point in the history
  44. [bugfix] fn:transform - cache key was too liberal.

    Some of the XQTS tests were getting failures due to falsely matching stylesheets in the stylesheet cache.
    
    This change properly distinguishes stylesheets.
    
    Where the stylesheet is a document, its base uri is the important part of the cache key. Where the stylesheet is a piece of text, we checksum the text.
    
     If the stylesheet doesn’t have a resolved stylesheet base URI or text to checksum, effectively we don’t cache them (well we do, but we use a unique date now()) as an element of the cache, so they will never match another request.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    0e34613 View commit details
    Browse the repository at this point in the history
  45. Remove debugging code

    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    5cc67f5 View commit details
    Browse the repository at this point in the history
  46. [feature] fn-transform “serialization-params”

    Serialization parameters.
    
    Serialization parameter reading/converting code is implemented in its own separate class.
    
    The code combines multiple Character maps manually as they are combined naively by supplied parameter combining (new map just overwrites old map in the parameter combination). The spec and XQTS tests require a merged combniation of maps.
    .
    Serialization params can be lists so deal with this.
    
    cdata-section-elements should be multi-valued.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    1cc159a View commit details
    Browse the repository at this point in the history
  47. [feature] fn:transform - XSLT compilation errors

    Improve error reporting on stylesheet compilation by handling error report exceptions made by the compiler as it progresses, storing these and using the exceptions from the report to be more specific than the standard “compilation didn’t work” exception that is thrown at exit of compilation.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    a563087 View commit details
    Browse the repository at this point in the history
  48. [testsuite] fn:transform UT for XQTS transform-68

    Add a unit test which confirms that the ‘vendor’ ‘requested-property’ works - which it does not as yet.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    74402d9 View commit details
    Browse the repository at this point in the history
  49. [feature] fn:transform - requested-properties

    Validate “requested-properties” against the system properties of the transformer implementation we are calling (Saxon).
    
    fn:transform will proceed if the requested properties match those provided by the transformer.
    fn:transform will raise an exception if any requested property does not match.
    
    No effort is made to deal with or to configure numeric values, so a request for product-version 2.1 will NOT be satisfied by product-version 2.3. Strictly, this behavious conforms to the spec https://www.w3.org/TR/xpath-functions-31/#func-transform, though in some cases it is not terribly helpful.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    20dc1f1 View commit details
    Browse the repository at this point in the history
  50. [testsuite] fn:transform UT requested-properties

    Implementation of “requested-properties” for fn:transform
    Add a unit test for the property “supports-namespace-axis”
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    dee3f24 View commit details
    Browse the repository at this point in the history
  51. fn:transform - convert XPath error from Saxon call

    Initial attempt at returning a correct error code per fn:transform specification and consistent with error codes returned by the Saxon transformer which is used internally.
    
    Figure out if an an XPathException from Saxon (a saxon class) or an eXist XPathException was a cause of an exception in Saxon invocation.
    
    Return a directly wrapped eXist XPathException as the cause of a new eXist XPathException.
    Return a wrapped Saxon XPathException as the cause of a new eXist XPathException.
    
    Generate/convert/wrap into an appropriate eXist XPathException.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    f2bddb9 View commit details
    Browse the repository at this point in the history
  52. [feature] fn:transform post-process function

    Read the post-process parameter, and if it is supplied and is a function, apply it to the output of the transformation as a final step in generating the output of fn:transform.
    
    The post-process function is applied possibly multiple times, once to the main output and once to every secondary output document. The final result is a map with the same keys as before post processing, but with post processed transformed values replacing transformed values.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    0702a6e View commit details
    Browse the repository at this point in the history
  53. [bugfix] fn:transform RAW destination for results

    Code for xsl:result-document could not create a destination when the output format was RAW. This was an oversight. Allow this to happen.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    8fb3281 View commit details
    Browse the repository at this point in the history
  54. fn:transform - simplify path to invoke transformer

    The stages of invocation of the XSLT transformer have been generalised/abstracted enough as we worked through the development that some simplification is now possible.
    
    Several cases collapse together, because of the Delivery abstraction that delivers the result in the configured form.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    9ce9b10 View commit details
    Browse the repository at this point in the history
  55. fn:transform - fixes to IntelliJ code inspections

    Accept changes proposed by IntelliJ code inspections.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    9543567 View commit details
    Browse the repository at this point in the history
  56. [bugfix] fn:transform - clean up error handling

    When the cause chain for an error contains an XPathException in native eXist, or the Saxon type for an XPathException, work harder to get the correct error code out of that cause, and reflect it in the XPathException ultimately thrown out of FnTransform.
    
    This has an effect on the error thrown by XQTS test transform-68, which becomes consistent with the proposed test suite fix here w3c/qt3tests#44
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    c2d9f54 View commit details
    Browse the repository at this point in the history
  57. fn:transform - refactor into own package

    The fn:transform implementation is large, and has accumulated many static and dynamic subclasses of FnTransform. This change creates its own package, and creates several top level classes in this package.
    
    The FnTransform module itself becomes a much smaller stub around a call into a Transform object which is part of the new package.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    b269542 View commit details
    Browse the repository at this point in the history
  58. fn:transform - tidy up unit tests

    Unit tests for fn:transform are mostly composed of convenient UT re-interpretations of the XQTS test suite. There are a lot, so collect them in a subdirectory.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    563edbd View commit details
    Browse the repository at this point in the history
  59. [bugfix] fn:transform refactor had multi doc bug

    Broken in the refactor. The refactored code was fetching secondary result documents from the wrong delivery object, so the secondary results were non-existent.
    
    Fetch from the correct delivery object.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    22fef81 View commit details
    Browse the repository at this point in the history
  60. Copy the full SHA
    b09da11 View commit details
    Browse the repository at this point in the history
  61. [bugfix] AnyURI should not be string subtype

    This seems to break a number of tests outside of fn:transform. Instead, adapt the option handling for fn:transform to do an explicit check on the case of requiring a string, and supply the StringValue of an atomic value if the value is not of string subtype.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    3f41d99 View commit details
    Browse the repository at this point in the history
  62. [bugfix] fn:transform - sonartype check

    fix flagged vulnerability
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    067c8b2 View commit details
    Browse the repository at this point in the history
  63. fn:transform - remove redundant code

    All XQTS tests work within the raw Saxon to eXist conversion code we have, so remove the fallback conversion-via-serialization, which incidentally helps coverage checking.
    alanpaxton committed Aug 4, 2022
    Copy the full SHA
    ced4937 View commit details
    Browse the repository at this point in the history
  64. Copy the full SHA
    7647cfc View commit details
    Browse the repository at this point in the history
  65. Copy the full SHA
    7f58927 View commit details
    Browse the repository at this point in the history
  66. Copy the full SHA
    36e490e View commit details
    Browse the repository at this point in the history

Commits on Aug 8, 2022

  1. Copy the full SHA
    623615e View commit details
    Browse the repository at this point in the history
  2. [bugfix] fn:transform - race condition

    XQTS tests were intermittently getting the wrong error message becase we were pullling it as the last error from a shared global error listener (error logger). Make an individual listener for each compilation/request which also side-effects the write to the shared logger.
    alanpaxton committed Aug 8, 2022
    Copy the full SHA
    a27be64 View commit details
    Browse the repository at this point in the history

Commits on Aug 9, 2022

  1. fn:transform - some sonarcloud observation fixes

    Cleaned up the ones which make sense.
    
    Not cleaned up - functions with high complexity where the complexity seems essential to the function.
    
    Not cleaned up - old code we have just brushed past lightly, and which sonarcloud has consequently highlighted.
    alanpaxton committed Aug 9, 2022
    Copy the full SHA
    339e40d View commit details
    Browse the repository at this point in the history

Commits on Aug 10, 2022

  1. fn:transform - review feedback

    Turn XSLT version number into an XSLTVersion class to be more explicit about precise versions, and to avoid potential float equality issues (2.99999999 != 3.0)
    
    Declaration order - member variables first
    
    Clarify a commented-out line
    alanpaxton committed Aug 10, 2022
    Copy the full SHA
    720a2cb View commit details
    Browse the repository at this point in the history