Basic use

Example 1

The example below demonstrates how the mod_transform module would be used to apply a single XSLT stylesheet to static XML pages.

Listing 1
  1. DocumentRoot "/var/www/mad-hacking/website"
  2.  
  3. <Directory "/var/www/mad-hacking/website">
  4.     Order allow,deny
  5.     Allow from all
  6.  
  7.     AddOutputFilter XSLT .xml
  8.  
  9.     TransformOptions ApacheFS XIncludes PreventRecursion
  10.     TransformSet     /style/site/xsl/layout.xsl
  11. </Directory>
Example code demonstrating basic use of the mod_transform module

As you can see the AddOutputFilter directive (on line 7) is used to associate files with the .xml extension with the XSLT transformation filter provided by the mod_transform module.

The TransformOptions directive (on line 9) specifies the options we wish the transform to use. These options are briefly described below.

  • The first option in our example, ApacheFS, is used when the paths specified in our XML and XSLT files should be resolved relative to the DocumentRoot and should use the structure of the web-site if multiple directories are used.

    This is accomplished internally using the sub-request mechanism. As a result of this any XML files which are included into other documents using either the xinclude directive or the document() function may be processed multiple times. The third directive, PreventRecursion, may be used to resolve this issue.

  • The second option in our example, XIncludes, indicates that we wish to be able to use the xinclude directive in our XML source files to include other documents. As mentioned above this may lead to recursive requests when including another XML document.

  • Finally, the PreventRecursion option is used to ensure that any files included using the xinclude directive or the document() function will not have any XSLT stylesheets applied to them and instead will be served directly.

Lastly we use the TransformSet directive (on line 10) to specify the XSLT stylesheet which should be used to process our documents. As we have used the ApacheFS option this path should be relative to the DocumentRoot directory.