arrow-down

XSLT Library

Contents

xp 7.+ blue

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:2.+'
}

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.

Compatibility

If you are upgrading from one of the early versions of the lib (before 2.0.0) to 2.0.0 or higher, make sure you are using correct reference: /lib/xslt (not /lib/xp/xslt or /site/lib/xp/xslt).


Contents

Contents

AI-powered search

Juke AI