XXSLT module can simplify:
Look at the example at the end of this document.
Put all sources to correct directories: (*.c, *.h, config)
When compiling from source use standard -add-module option as below:
./configure --add-module=src/http/modules/xxslt --add-module=src/http/modules/download --add-module=src/http/modules/mxcache
After configure simply compile and install nginx from terminal:
make make install
XXSLT Module:
MXCache Module:
Download Module:
location /xxslt { xxslt on; xxslt_cache_expire 5m; xxslt_cache_timeout 200ms; xxslt_download_timeout 1500ms; mxcache on; mxcache_server_ip 127.0.0.1; mxcache_server_port 11211; }
<include ... />
Atributes:
Module allows to download XML data and define XSL stylesheets directly in processed document.
You can use xslt with include tag in two ways:
<xxslt> <include ... name="name1" dca="xslt" /> [xslt instructions] </xxslt>
<xxslt> <include ... name="name2" dca="xslt" /> </xxslt> [...] <xxslt> [xslt instructions] </xxslt>
Pay attention to the fact that the xml data included above are available below in the page. Structure of the global XML document containing all includes is as follows:
<inc> <name1> [included data] </name1> <name2> [included data] </name2> [...] </inc>
Example:
<html> [...] <xxslt> <include src="http://rss.weather.com.au/nsw/sydney" name="weather" dca="xslt" alt="weather_rss_error.xml" ttl="300" maxwait="1500"/> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:w="http://rss.weather.com.au/w.dtd"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" encoding="UTF-8"/> <xsl:template match="/"> <xsl:for-each select="//weather/rss/channel/item/w:forecast"> <div> <img src="{@iconUri}" alt="{@iconAlt}" class="weather" /> <ul class="weather"> <li><b>Day: </b> <xsl:value-of select="@day" /></li> <li><b>Min temp: </b> <xsl:value-of select="@min" />C </li> <li><b>Max temp: </b> <xsl:value-of select="@max" />C </li> </ul> </div> </xsl:for-each> </xsl:template> </xsl:stylesheet> </xxslt> [...] <html>
Module will download RSS containing XML data and present it using declared stylesheet. If an error occurs rrs_error.xml will be used instead of the rss. Includes are cached if mxcache module is enabled.
When dca is set to "none" (default), an included object will be included as flat text.
Example:
<html> [...] <div id="menu"> <xxslt> <include src="menu1.html" name="menu" ttl="500"/> </xxslt> </div> [...] </html>
This will include content of the file into the page source. Includes are cached if mxcache module is enabled.