Project

Profile

Help

Bug #4723

closed

XSLT 3 using function-lookup gives TypeError: h is not a function

Added by Martin Honnen over 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
XSLT Conformance
Sprint/Milestone:
-
Start date:
2020-09-04
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
2
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

I have tried to run an XSLT 3 example using function-lookup that works fine with Saxon Java 10 HE through Saxon-JS 2 under Node with xslt3 but there it gives an error "TypeError: h is not a function".

Reduced test case is:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="3.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    exclude-result-prefixes="#all"
    expand-text="yes">
    
    <xsl:mode on-no-match="shallow-copy"/>
    
    <xsl:template match="example">
        <xsl:copy>{
            function-lookup(xs:QName(function), count(arguments/arg))
            =>
            apply(array { arguments/arg })
        }</xsl:copy>
    </xsl:template>
    
    <xsl:template match="/" name="xsl:initial-template">
        <xsl:next-match/>
        <xsl:comment xmlns:saxon="http://saxon.sf.net/">Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')}</xsl:comment>
    </xsl:template>
    
</xsl:stylesheet>

input sample:

<root>
    <example>
        <function>fn:concat</function>
        <arguments>
            <arg>a</arg>
            <arg>b</arg>
            <arg>c</arg>
        </arguments>
    </example>
</root>

Result with xslt3:

<?xml version="1.0" encoding="UTF-8"?><root>
    Transformation failure: TypeError: h is not a function
Transformation failed: TypeError: h is not a function

Expected result is the one I get with Saxon Java:

<?xml version="1.0" encoding="UTF-8"?><root>
    <example>abc</example>
</root>
Actions #1

Updated by Michael Kay over 3 years ago

Added XSLT3 test case function-lookup-008; confirmed the failure.

With the debug version of the code we get:

TypeError: $untypedConversion$$ is not a function
    at /Users/mike/GitHub/saxon-js-enterprise/build/temp/js/build/SaxonJS2N.debug.js:11919:41
    at Array.map (<anonymous>)
    at Object.$coerce$$ [as coerce] (/Users/mike/GitHub/saxon-js-enterprise/build/temp/js/build/SaxonJS2N.debug.js:11918:41)
    at $$CoreFunction$$$.$$XdmFunction$$$$convertArgs$ [as convertArgs] (/Users/mike/GitHub/saxon-js-enterprise/build/temp/js/build/SaxonJS2N.debug.js:3820:77)
    at $$CoreFunction$$$$evaluate$ [as evaluate] (/Users/mike/GitHub/saxon-js-enterprise/build/temp/js/build/SaxonJS2N.debug.js:3868:48)
    at applyFn (/Users/mike/GitHub/saxon-js-enterprise/build/temp/js/build/SaxonJS2N.debug.js:9836:24)
    at /Users/mike/GitHub/saxon-js-enterprise/build/temp/js/build/SaxonJS2N.debug.js:12701:14

This corresponds to line 3013 in Expr.js; variable untypedConversion is undefined, because RT (required type) is anyAtomicType, which does not have a cast method. Effectively we're invoking the function conversion rules with a supplied value that's the untypedAtomic value "a", and a required type that's anyAtomicType (being the declared argument type of fn:concat#3), and I think the correct action in that situation is to perform no conversion.

Actions #2

Updated by Debbie Lockett over 3 years ago

  • Assignee set to Debbie Lockett
Actions #3

Updated by Michael Kay over 3 years ago

  • Status changed from New to In Progress
  • Assignee changed from Debbie Lockett to Michael Kay

Changed the code so if reqCode="A" (meaning xs:anyAtomicType) we do no conversion.

The test no longer crashes, but it does not produce the expected results. I'm having trouble understanding the failure; when the test is run from the command line (rather than the test driver) it seems to produce the correct output.

Actions #4

Updated by Michael Kay about 3 years ago

  • Status changed from In Progress to Resolved

The test appears to be working both when run directly from the command line, and when run from the test driver. Marking as resolved.

Actions #5

Updated by Community Admin about 3 years ago

  • Applies to JS Branch 2 added
  • Applies to JS Branch deleted (2.0)
Actions #6

Updated by Debbie Lockett about 3 years ago

  • Fix Committed on JS Branch 2 added
Actions #7

Updated by Debbie Lockett almost 3 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in JS Release set to Saxon-JS 2.1

Bug fix applied in the Saxon-JS 2.1 maintenance release.

Please register to edit this issue

Also available in: Atom PDF Tracking page