To use this library in your JavaScript code, you first need to require it:
var xsltLib = require('/lib/xslt');
Then, you will need to find the view. For instance, if you have a part, Fruit, you resolve the part with:
var view = resolve('view/fruit.xslt');
All the variables used in the view must be gathered, from request objects, back-end storage or whatever source you want to use. These should be put into a JSon object that is sent to the render function:
var model = {
fruits: [
{
name: 'Apple',
color: 'Red'
},
{
name: 'Pear',
color: 'Green'
}
]
};
var result = xsltLib.render(view, model);
This lib have only one method:
This will create a document, based on the template in the view, and the content in the model. Normally this is an HTML-document, but XSL may be used to create text-documents of any type.
Parameters
-
view
(object) Location of the view. Use resolve(..) to resolve a view. -
model
(object) Model that is passed to the view.