How to transform an XML Document with XSLT into a new XML Document in Node.JS

I’m just going to come out and say it: today’s tutorial topic is so dry and boring that we are going to skip it entirely. Why go through the drudgery when I can just show you how to use an API to get the same results in a small fraction of the time?

To use our API, we will need to install its client:

npm install cloudmersive-convert-api-client --save

Then our results are just a function call away:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertDataApi();var inputFile = "/path/to/file"; // File | Input XML file to perform the operation on.var transformFile = "/path/to/file"; // File | Input XSLT file to use to transform the input XML file.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDataXmlTransformWithXsltToXml(inputFile, transformFile, callback);

And finally, we just need to input our XML file to be transformed and the XLST file as well. Your return will be the transformed file, easy as that.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store