home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeWeb Design in a NutshellSearch this book

18.5. XSSI

Apache also supports XSSI (eXtended Server Side Includes), which provides more advanced command functions (and, consequently, uses code that is a bit more complicated for non-programmer types).

This section presents a brief overview of features unique to XSSI. For the nitty-gritty how-to information, see the Apache 1.3 mod_include documentation at http://www.apache.org/docs/mod/mod_include.html. There are several good articles on XSSI available on the Webmonkey site (http://hotwired.lycos.com/webmonkey/backend/apache_xssi/index.html), which provide good explanations and examples of real-world implementations of XSSI. Despite being several years old, the information is still valid.

18.5.1. Flow Control Elements

Flow control elements are a set of if/else commands (similar to if statements used in a programming language) that allow authors to create conditional commands. Using flow control elements, authors can make documents display differently based on specific variables (the "test conditions"). For instance, you could publish one version of your page for users accessing it with the Navigator browser and another for Internet Explorer users.

The basic flow elements are:

<!--#if expr="test_condition" -->
<!--#elif expr="test_condition" -->
<!--#else -->
<!--#endif -->

The first command contains the if statement that causes the server to test for a condition (e.g., if the browser is Navigator). If it is found to be true, the server prints the text or executes any SSI commands immediately following the if command. If the test condition posed by the if statement is false, the elif statement (which stands for "else if") is tried next. If the elif test condition is true, the server prints or executes whatever follows it.

Otherwise, the server prints or executes whatever comes after else, which acts as a catch-all for every other condition that might exist. An if/else statement like this can have as many elifs as you want to add, each of which is tested in turn, and it does not require that you have an else statement at the end -- in which case, if none of the if or elif statements are found to be true, the server does not do anything.

The endif element ends the if element and is required.

In the following example, a greeting is customized based on the user's browser:

<!--#if expr="\"$HTTP_USER_AGENT\" = \"Mozilla\"" -->
Welcome Netscape User! 
<!--#elif expr="\"$HTTP_USER_AGENT\" = \"Explorer\"" -->
Welcome Internet Explorer User!
<!--#else -->
Welcome!
<!--#endif -->

As you can see, this is where a little programming knowledge comes in handy for getting the most out of SSI.

18.5.2. Setting Variables

The standard available environment variables were introduced earlier in this chapter. XSSI adds the capability to create your own variables using the set element as follows:

<!--#set var="category" value="help" -->

Your customized variables can then be used as test conditions using the flow control elements listed earlier.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.