ngx_http_xslt_module模块基本指令整理

  categories:资料  author:

原创文章,转载请指明出处并保留原文url地址

本文主要针对nginx的ngx_http_xslt_module模块做简单介绍,本文具体包括如下指令:

ngx_http_xslt_module模块是一个使用多个 XSLT stylesheets(样式表)将xml相应进行相应变换的过滤器模块。

这个模块不是内建模块,他应该采用–with-http_xslt_module配置参数使能编译。

这个模块需要libxml2及libxslt库的支持。

配置示例

    location / {

        xml_entities    /site/dtd/entities.dtd;

        xslt_stylesheet /site/xslt/one.xslt param=value;

        xslt_stylesheet /site/xslt/two.xslt;

    }

Nginx原文:

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;

    }

1. xml_entities

syntax:

xml_entities   path;

default:

context:

http, server, location

指定一个定义字符实体的DTD文件。这个文件在配置阶段被编译。由于技术原因这个文件不能使用外部的子声明在xml中的,为此相关声明将被忽略,而不是用特定文件指定。这个文件不能包括xml结构,他应该仅仅包括足够的必要的字符声明,例如:

<!ENTITY nbsp " ">

Nginx原文:

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 " ">

2. xslt_param

syntax:

xslt_param    parametervalue;

default:

context:

http, server, location

This directive appeared in version 1.1.18.

给XSLT样式表定义参数。相应的参数值被看做XPath表达式。参数值可以包含变量。为了传递一个字符串的值给样式表, xslt_string_param指令可以被使用。

可有多个xslt_param指令。 若是在当前级别没有定义 xslt_param 和 xslt_string_param指令, 这些指令继承自前一个基本或者上一层级别的相关配置。

Nginx原文:

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.

3. xslt_string_param

syntax:

xslt_string_param   parametervalue;

default:

context:

http, server, location

This directive appeared in version 1.1.18.

为XSLT样式表定义字符串参数, XPath表达式不被解释,参数值可以包括变量。
可能存在多个xslt_string_param指令, 在当前配置级别没有定义xslt_param and xslt_string_param指令, 则从前一个级别继承相关配置。

Nginx原文:

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.

4. xslt_stylesheet

syntax:

xslt_stylesheet    stylesheet[parameter=value …];

default:

context:

location

定义 XSLT样式表及他的可选参数。样式表是在配置阶段被编译。

参数既可以被独立指定,也可以用“:”分割的单行进行成组的指定参数。如果参数包括“:”字符, 参与应该用“%3A”转义。另外,libxslt库要求对非字母的字符参数用双引号或者单引号将参数扩起来,例如:

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

参数描述可以包括变量。例如, 整个行参数可以从一个单一的变量。

location / {

        xslt_stylesheet /site/xslt/one.xslt

                        $arg_xslt_params

                        param1=’$value1′:param2=value2

                        param3=value3;

    }

可以指定多个样式表;在这种情况下,他们将依次按指定的顺序被应用。

Nginx原文:

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.

5. xslt_types

syntax:

xslt_types    mime-type…;

default:

xslt_types text/xml;

context:

http, server, location

使变换功能在除了“text/xml”类型的相应以外的MIME类型的相应中也工作。“*”值匹配任何类型的相应。如果相应的结果是html类型, 则变换后的MIME 类型是“text/html”。

Nginx原文:

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”.



快乐成长 每天进步一点点