Project

Profile

Help

[Saxon-JS] Put the result of a transformation on a javascript variable

Added by Rémi Ossant about 6 years ago

Hello everyone,

According to the documentation, it's possible to get the reuslt of a transformation when using Saxon-JS with destination: "application".


	SaxonJS.transform({
		stylesheetLocation: 'xslFile.sef',
		sourceLocation: 'xmlFile.xml',
		destination: 'application'
	});

the transformation works fine but I'm not sure to undertand how to get the result and to put the value into a variable.

Thank you in advance for your help!


Replies (4)

Please register to reply

RE: [Saxon-JS] Put the result of a transformation on a javascript variable - Added by Debbie Lockett about 6 years ago

The transformation result is attached to the options object supplied to SaxonJS.transform(), but because you've supplied an object directly, I can see it's harder to get at! Try something like the following:


var options = {
   stylesheetLocation: 'xslFile.sef',
   sourceLocation: 'xmlFile.xml',
   destination: 'application'
}
SaxonJS.transform(options);
var result = options.principalResult;

Alternatively, a callback function can be supplied as the second argument to SaxonJS.transform(). The callback function is called when the transformation is complete, with the transformation result (the value of options.principalResult) supplied as its argument.

(For future reference, there's a separate forum specifically for Saxon-JS help at https://saxonica.plan.io/projects/saxon-js/boards)

RE: [Saxon-JS] Put the result of a transformation on a javascript variable - Added by Rémi Ossant about 6 years ago

Thanks a lot for your answer and sorry for the mistake about the forum...

I've tried your solution and unfortunately I can't see if the result is contain on the variable, I've tried some :


 alert(result);
console.log(result);

or to put the result into an element with something like :


document.getElementById('test').innerHTML = result;

but it returns "undefined". Do you know what's the problem ?

Thank again for your help!

RE: [Saxon-JS] Put the result of a transformation on a javascript variable - Added by Debbie Lockett about 6 years ago

Ah yes, sorry, you do need to use a callback after all (so that you only try to get the result from the transformation once it is complete!) Try something like


SaxonJS.transform(options, function(result) {
   alert(result);
   // or whatever
});

RE: [Saxon-JS] Put the result of a transformation on a javascript variable - Added by Rémi Ossant about 6 years ago

I didn't try the callback solution ... and it works fine!

Thank you very much for your quick answers and your help!

    (1-4/4)

    Please register to reply