Project

Profile

Help

Bug #5430

closed

Use of deliverResultDocument in SaxonJS.transform options causes error "Unsupported result-document destination undefined"

Added by Martin Honnen over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
API
Sprint/Milestone:
Start date:
2022-03-28
Due date:
% Done:

100%

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

Description

As reported on Slack, the use of deliverResultDocument with Saxon-JS (tested with2.3 and Node.js 14) can give an error "Unsupported result-document destination undefined".

The JavaScript code I have tried is

const path = require('path');

var urlModule = require('url');

const baseURI = urlModule.pathToFileURL(path.join(path.resolve('.'), 'foo.xml'));

console.log(`baseURI: ${baseURI.href}`);

const SaxonJS = require('saxon-js');

var options = {
  'stylesheetLocation' : 'sheet1.sef.json',
  'sourceLocation' : 'input1.xml',
  'destination' : 'serialized',
  'baseOutputURI' : baseURI.href,
  'deliverResultDocument': function(uri) {
     return {
       'destination' : 'serialized',
       'save' : function(resultUri, result, encoding) {
          console.log(resultUri, result);
        }
     };
   }
};

SaxonJS.transform(options); //SaxonJS.transform(options, 'sync');

console.log(options.principalResult);

When I run that (sef.json and input sample are attached) I get

baseURI: file:///C:/Users/marti/some-path/some-dir/foo.xml

C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4167
c;c=c.actor;c.C&&F(c)(L,d)}},valueOf:function(h){var L=Wd.Oa(h),d={};Wd.Bb(h,"d")&&(d.DISABLE_ESCAPING=!0);return function(c,k){c=l(L(c));k.text(c,d)}}};return{Pg:w,elaborateForPush:e,getComplexContentOutputter:function(h){return new a(h)},push:function(h,L,d){if("undefined"===typeof d)throw rb.lb(Error().stack),new K("No output for "+m(h));if(r[h.N]){var c=e(h);try{c(L,d)}catch(n){throw n instanceof K&&!n.xsltLineNr&&nb(n,h),n;}}else{c=Wd.elaborate(h);try{for(var k=c(L),q;null!=(q=k.next());)d.append(q)}catch(n){throw n instanceof



                         ^
Error
    at new K (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:3887:513)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4436:297
    at L (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4135:641)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4164:69
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4136:33
    at Array.forEach (<anonymous>)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4136:6
    at Object.push (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4167:370)
    at e.uf (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4745:502)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4743:284
    at wc.ba.forEachItem (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:3985:583)
    at e.Ib (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4743:251)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4741:414
    at Object.u [as rj] (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4139:435)
    at SC (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4741:310)
    at e.uf (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4746:72)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4743:284
    at wc.ba.forEachItem (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:3985:583)
    at e.Ib (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4743:251)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4741:414
    at Object.u [as rj] (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4139:294)
    at SC (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4741:310)
    at e.uf (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4746:72)
    at e.Qk (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4744:70)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4165:171
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4136:33
    at Array.forEach (<anonymous>)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4136:6
    at Object.push (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4167:370)
    at e.uf (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4745:502)
    at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4743:284
    at wc.ba.forEachItem (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:3985:583)
    at e.Ib (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4743:251)
    at e (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4758:179)
    at t (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4761:137)
    at Object.transform (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4781:375)
    at Object.<anonymous> (C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\saxon-js-xsl-result-document-uri-tests\runTransformSyncCaptureResultsExplicitly1.js:26:9)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  message: 'Unsupported result-document destination undefined',
  name: 'XError',
  code: 'XXXX9999',
  xsltLineNr: '15',
  xsltModule: 'sheet1.xsl'
}

Files

input1.xml (71 Bytes) input1.xml Martin Honnen, 2022-03-28 23:25
runTransformSyncCaptureResultsExplicitly1.js (740 Bytes) runTransformSyncCaptureResultsExplicitly1.js Martin Honnen, 2022-03-28 23:25
sheet1.sef.json (6.54 KB) sheet1.sef.json Martin Honnen, 2022-03-28 23:25
sheet1.xsl (876 Bytes) sheet1.xsl Martin Honnen, 2022-03-28 23:25
Actions #3

Updated by Norm Tovey-Walsh over 2 years ago

  • Status changed from New to In Progress

Part of the problem, perhaps not the whole problem, is that the references to the destination and save properties were being rewritten by the Closure compiler.

Actions #4

Updated by Norm Tovey-Walsh over 2 years ago

Indeed, the crash goes away if we replace delivery.save and delivery.destination with delivery["save"] and delivery["destination"], respectively. Now the question is, are there other code paths where save and destination will have been rewritten by the Closure compiler?

Actions #5

Updated by Norm Tovey-Walsh over 2 years ago

  • Status changed from In Progress to Resolved
  • Applies to JS Branch Trunk added
  • Fix Committed on JS Branch 2, Trunk added

I've persuaded myself that the destination and save properties always come from external options and therefore the Closure renaming simply has to be avoided.

Actions #6

Updated by Norm Tovey-Walsh over 2 years ago

  • Status changed from Resolved to In Progress

No, there are some other definitions that are in the initialization code.

Actions #7

Updated by Debbie Lockett over 2 years ago

  • Status changed from In Progress to Resolved

Unit test nodejs/iss5430 has been added.

To improve the code, and better avoid the Closure compiler renaming, I've added a class ResultDocumentDeliverer for the object returned from the deliverResultDocument function. (Defined in transform.js and Externs.js.) This object has properties "destination" and "save".

(The documentation also included details about a property "receiver", but this does not appear to be implemented, so I have removed this.)

Committed on saxonjs2 and main branches.

Actions #8

Updated by Debbie Lockett over 2 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in JS Release set to SaxonJS 2.4

Bug fix applied in the SaxonJS 2.4 maintenance release.

Please register to edit this issue

Also available in: Atom PDF Tracking page