Support #5188


Asynchronous JavaScript Function Call with Map Return

Added by David Camps 9 months ago. Updated 6 months ago.

Start date:
Due date:
% Done:


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


I am prototyping a transform using SaxonJS 2.3.0 under NodeJS. The intent is to have the XSL issue a MongoDB query and receive the JSON result as an XDM map that can be used in the XSL like $map(‘name’) or map:get($map, ‘name’). I have been around and around exploring different techniques to get javascript (js) to return a usable map to the transform. I have been successful in passing JSON to the transform with:

const jsonResult = { id: 1, name: 'name1' }

const jsonMap = SaxonJS.getResource({ text: JSON.stringify(jsonResult), type: 'json' }).then( doc => { return doc; }, rej => { debugger; } );

Promise.all([…, jsonMap]).then((values) => { var […, jsonMap] = values; var htmlOutput = SaxonJS.transform({ stylesheetParams: { … jsonMap: jsonMap },

But I can’t figure out how to access the promise(d) result in the transform with:

class class1 { constructor() { } getJasonMap() {

	var json = {
		id: 1,
		name: 'name1'

	var jsonMap = SaxonJS.getResource({
		text: JSON.stringify(json),
		type: 'json'
		map => { return map; },
		rej => { debugger; }
	return jsonMap;
} // getJasonMap

} // class1

var instance = new class1();

var htmlOutput = SaxonJS.transform({ stylesheetParams: { … instance: instance },

<xsl:variable name="resultMap" as="map(*)" select="ixsl:call($instance, 'getJasonMap', [])" />

If I skip the SaxonJS.getResource() and just return the straight json, it sort of works, but things get sketchy where $map(‘id’) works in the XSL and map:get($map, ‘id’) does not work or visa versa. If I am making choices about what technique to use, it needs to be something solid that seems to be supported rather than something that works one way and not the other.

I have also toyed with creating my own map in the js using “var map = new SaxonJS.XDMMAP()” and adding items with:

var key1 = new SaxonJS.XdmAtomicValue('id1'); var value1 = new SaxonJS.XdmAtomicValue('value1'); map.put(key1, value1);

--- or ---

map.inSituPut(key1, value1);

but even though the $map does not generate any errors when used in the transform, I cannot get any values back (i.e. $map(‘id’) returns nothing).

Where should I go with this attempt to get maps returned from js functions in a reliable and support way?

BTW, the SEF was generated in the test program with SaxonJS.compile()

Please register to edit this issue

Also available in: Atom PDF Tracking page