nginx

Module ngx_http_xslt_module


english
русский

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

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

trac
wiki
twitter
nginx.com
blog
Example Configuration
Directives
     xml_entities
     xslt_last_modified
     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 at 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 a specially defined file is used instead. This file should not describe the XML structure. It is enough to declare just the required character entities, for example:

<!ENTITY nbsp "&#xa0;">

syntax: xslt_last_modified on | off;
default:
xslt_last_modified off;
context: http, server, location

This directive appeared in version 1.5.1.

Allows preserving the “Last-Modified” header field from the original response during XSLT transformations to facilitate response caching.

By default, the header field is removed as contents of the response are modified during transformations and may contain dynamically generated elements or parts that are changed independently of the original response.

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

This directive appeared in version 1.1.18.

Defines the 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 the 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 at 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 parameters description 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. 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 transformation result is an HTML response, its MIME type is changed to “text/html”.