nginx

Module ngx_http_xslt_module


english
русский

简体中文
עברית
日本語
türkçe

news
about
download
security advisories
documentation
pgp keys
faq
links
books
support
donation

trac
wiki
twitter
nginx.com
Example Configuration
Directives
     xml_entities
     xslt_param
     xslt_string_param
     xslt_stylesheet
     xslt_types

The ngx_http_xslt_module (0.7.8+) is a filter that transforms XML responses using one or more XSLT stylesheets.

This module is not built by default, it should be enabled with the --with-http_xslt_module configuration parameter.

This module requires the libxml2 and libxslt libraries.

Example Configuration

location / {
    xml_entities    /site/dtd/entities.dtd;
    xslt_stylesheet /site/xslt/one.xslt param=value;
    xslt_stylesheet /site/xslt/two.xslt;
}

Directives

syntax: xml_entities path;
default:
context: http, server, location

Specifies the DTD file that declares character entities. This file is compiled during the configuration stage. For technical reasons the module is unable to use the external subset declared in the processed XML, so it is ignored and instead a specially defined file is used. This file should not describe the XML structure, it is enough to only declare the required character entities, for example:

<!ENTITY nbsp "&#xa0;">

syntax: xslt_param parameter value;
default:
context: http, server, location

This directive appeared in version 1.1.18.

Defines parameters for XSLT stylesheets. The value is treated as an XPath expression. The value can contain variables. To pass a string value to a stylesheet, the xslt_string_param directive can be used.

There could be several xslt_param directives. These directives are inherited from the previous level if and only if there are no xslt_param and xslt_string_param directives defined on the current level.

syntax: xslt_string_param parameter value;
default:
context: http, server, location

This directive appeared in version 1.1.18.

Defines string parameters for XSLT stylesheets. XPath expressions in the value are not interpreted. The value can contain variables.

There could be several xslt_string_param directives. These directives are inherited from the previous level if and only if there are no xslt_param and xslt_string_param directives defined on the current level.

syntax: xslt_stylesheet stylesheet [parameter=value ...];
default:
context: location

Defines the XSLT stylesheet and its optional parameters. A stylesheet is compiled during the configuration stage.

Parameters can either be specified separately, or grouped in a single line using the “:” delimiter. If a parameter includes the “:” character, it should be escaped as “%3A”. Also, libxslt requires to enclose parameters that contain non-alphanumeric characters into single or double quotes, for example:

param1='http%3A//www.example.com':param2=value2

The description of parameters can contain variables, for example, the whole line of parameters can be taken from a single variable:

location / {
    xslt_stylesheet /site/xslt/one.xslt
                    $arg_xslt_params
                    param1='$value1':param2=value2
                    param3=value3;
}

It is possible to specify several stylesheets; in this case they will be applied sequentially in the specified order.

syntax: xslt_types mime-type ...;
default:
xslt_types text/xml;
context: http, server, location

Enables transformations in responses with the specified MIME types in addition to “text/xml”. The special value “*” matches any MIME type (0.8.29). If the result of transformation is an HTML response, its MIME type is changes to “text/html”.