Project

Profile

Help

Bug #5490

open

Saxon-JS 2.4 fails to run Schxslt pipeline XSLT that tries to first compile Schematron schema to XSLT and then to apply that schema to validate an XML instance document: TypeError: Cannot read property 'childNodes' of undefined

Added by Martin Honnen 2 days ago. Updated about 21 hours ago.

Status:
New
Priority:
High
Assignee:
-
Category:
XSLT Conformance
Sprint/Milestone:
Start date:
2022-05-14
Due date:
% Done:

0%

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

Description

I have found a major regression with Saxon 2.4, I have a stylesheet that runs two XSLT transformations in a pipeline, the first step uses Schxslt 1.8.6 to compile a Schematron schema to XSLT, the second step applies the generated XSLT against an input XML document to validate that input XML against the Schematron schema and to generate an SVRL report. That worked fine for me with Saxon-JS 2.2 and 2.3 but in 2.4 fails with an error:

C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest>xslt3 -t -xsl:run-pipeline-for-svrl-and-apply-to-schema.sef.json -s:sample1.xml schema-uri=schematron-schema1.sch
SaxonJS 2.4 from Saxonica
Node.js version v14.16.0
SEF generated by SaxonJS 2.4 at 2022-05-14T12:47:24.253+02:00
Transformation failure: TypeError: Cannot read property 'childNodes' of undefined
Cannot read property 'childNodes' of undefined

When I run the code from Node.js I get a longer stack trace included that hopefully helps:

C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest>node app.js
C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest\node_modules\saxon-js\SaxonJS2N.js:4224
push:function(h,M,d){if("undefined"===typeof d)throw ob.fb(Error().stack),new L("No output for "+m(h));if(u[h.N]){var c=e(h);try{c(M,d)}catch(n){throw n instanceof L&&!n.xsltLineNr&&nb(n,h),n;}}else{c=Wd.elaborate(h);try{for(var l=c(M),q;null!=(q=l.next());)d.append(q)}catch(n){throw n instanceof L&&!n.xsltLineNr&&nb(n,h),n;}}},bj:g,Of:t,mh:r}}();var Ve=function(){function a(Q,ja,ca,z,A){function F(E){return null===n.Ma(E)}function I(E){return E.nodeType===B.nodeType&&(null===R?!0:n.ba(E).equals(R))}var S=A.fixed.evaluator;if(ja){var B=S.evaluate(ja,A).next();if(!B||!n.Q(B))throw new L("xsl:number/@select must yield a single node","XTTE1000");}else A.failIfNoCurrentFocus("XTTE0990","xsl:number"),B=A.getCurrentFocus();var R=n.ba(B),J=I;if(null!==ca){var fa=Ae.pd(ca);J=function(E){return Ae.matches(fa,E,A)}}if(null===z)ja=F;else{var ka=Ae.pd(z);
                                                                                                                                                                                                                                                                                       ^

TypeError: Cannot read property 'childNodes' of undefined
    at transform (C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4408:426)
    at C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4463:173
    at C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4477:57
    at Object.push (C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4224:232)
    at e (C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4816:245)
    at t (C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4820:320)
    at Object.transform (C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4840:413)
    at Object.<anonymous> (C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest\app.js:16:26)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m

I put the files in a Github repository: https://github.com/martin-honnen/SaxonJSSchxsltPipelineTest.

Actions #1

Updated by Martin Honnen 2 days ago

I have also created the branch https://github.com/martin-honnen/SaxonJSSchxsltPipelineTest/tree/UseSaxonJS23/SaxonJSSchxsltPipelineTest that uses Saxon-JS 2.3 and where the code works fine and outputs an SVRL report instead of giving that error:

C:\Users\marti\source\repos\SaxonJSSchxsltPipelineTest\SaxonJSSchxsltPipelineTest>node app.js
<?xml version="1.0" encoding="UTF-8"?>
<svrl:schematron-output xmlns:error="https://doi.org/10.5281/zenodo.1495494#error" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:schxslt-api="https://doi.org/10.5281/zenodo.1495494#api" xmlns:schxslt="https://doi.org/10.5281/zenodo.1495494" xmlns:svrl="http://purl.oclc.org/dsdl/svrl" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <svrl:metadata xmlns:dct="http://purl.org/dc/terms/" xmlns:skos="http://www.w3.org/2004/02/skos/core#">
      <dct:creator>
         <dct:Agent>
            <skos:prefLabel>Saxon-JS/2.3</skos:prefLabel>
         </dct:Agent>
      </dct:creator>
      <dct:created>2022-05-14T13:24:31.928+02:00</dct:created>
      <dct:source>
         <rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/">
            <dct:creator>
               <dct:Agent>
                  <skos:prefLabel>SchXslt/1.8.6 Saxon-JS/2.3</skos:prefLabel>
                  <schxslt.compile.typed-variables xmlns="https://doi.org/10.5281/zenodo.1495494#">true</schxslt.compile.typed-variables>
               </dct:Agent>
            </dct:creator>
            <dct:created>2022-05-14T13:24:30.896+02:00</dct:created>
         </rdf:Description>
      </dct:source>
   </svrl:metadata>
   <svrl:active-pattern documents="file:///C:/Users/marti/source/repos/SaxonJSSchxsltPipelineTest/SaxonJSSchxsltPipelineTest/run-pipeline-for-svrl-and-apply-to-schema.sef.json"/>
   <svrl:fired-rule context="root"/>
   <svrl:failed-assert location="/Q{}root[1]" test="@*">
      <svrl:text>root has no attributes.</svrl:text>
   </svrl:failed-assert>
   <svrl:successful-report location="/Q{}root[1]" test=". = 'This is an example.'">
      <svrl:text>root element has value 'This is an example.'</svrl:text>
   </svrl:successful-report>
</svrl:schematron-output>
Actions #2

Updated by Martin Honnen 2 days ago

To see whether the problem only occurs in the context of (a relatively complex code like) Schematron compilation I have now also added some files identity.xsl, identity.sef.json, run-and-apply-identity.js, run-and-apply-identity.xsl, run-and-apply-identity.sef.json and if you run node run-and-apply-identity.js you get the same error with Saxon-JS 2.4 as with the more complex Schematron samples while Saxon-JS 2.3 runs the identity transformation fine.

Actions #3

Updated by Norm Tovey-Walsh 2 days ago

Well, that is disappointing. I shall investigate and see if we need to do a 2.5.

Actions #4

Updated by Martin Honnen about 22 hours ago

I think the regression is due to the fix of https://saxonica.plan.io/issues/5039, previously the Saxon-JS code created always a document node, now it might create a document fragment node but the code processing a stylesheet expects a document nodes as at some point it wants to process all top level nodes by processing e.g. stylesheet.documentElement.childNodes, only now, with 2.4, stylesheet can be a document fragment node and document fragment nodes do not have a documentElement at all. That way the attempt to process a stylesheet that is formed as a fragment fails with the attempt to access childNodes on the undefined documentElement of the stylesheet.

Actions #5

Updated by Martin Honnen about 21 hours ago

If I change a line doing

for (ma = Aa(ha.documentElement.childNodes),
                    y = ma.next(); !y.done; y = ma.next())

to

for (ma = Aa(ha.documentElement ? ha.documentElement.childNodes : ha.childNodes),
                    y = ma.next(); !y.done; y = ma.next())

the Saxon-JS 2.4 code seems to be able to process the stylesheet fine.

I haven't checked whether there is other stylesheet processing code around that tries to process stylesheet.documentElement.childNodes.

Actions #6

Updated by Martin Honnen about 21 hours ago

I think the fix should rather be

                    for (ma = Aa(ha.documentElement ? ha.documentElement.childNodes : ha.firstElementChild.childNodes),
                    y = ma.next(); !y.done; y = ma.next())

Please register to edit this issue

Also available in: Atom PDF Tracking page