XSLT Library
Contents
| Versions 3.x target XP 8+. |
This library provides basic XSLT rendering functionality to create pages and parts using XSLT as the templating language.
dependencies {
include 'com.enonic.lib:lib-xslt:3.+'
}
Usage
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);
API
This lib have only one method:
render
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.