Example 1: Saving Bandwidth by Using XSLT for Headers and Footers - Page 3
October 28, 2002
Let's start by taking a normal web page, and seeing how we can use XSLT to
add some standard content to the page. In this example, we'll add a header
and footer to a simple page of XHTML.
All of the examples in this chapter can be downloaded from the glasshaus
web site at http://www.glasshaus.com. The downloadable versions have additional
comments so you don't need to keep referring back to the book as you read
them.
The benefits of doing this in XSLT are as follows:
·
We only need to store one copy of the header and footer code
to cover every page on the site, making it easy to change them globally without
editing every single page.
·
Users only need to download the header and footer XSLT code
once, even though they are used on every page in the site. This can give bandwidth
savings, which is important if your service provider charges by the megabyte,
or if you are supporting modem users.
·
Server processing is reduced as all the work is being done
on the client.
How else could we do it? We could manually
add the header and footer to every web page, but this would result in a site
maintenance nightmare, especially for a large site. The other alternatives
are as follows:
·
By using Server-Side Includes (SSI)
to include standard header and footer content on every page.
·
By using a scripting language (such as ASP, PHP, or JSP) to
generate web pages with the header and footer included.
Although these methods share the first advantage of only storing one copy
of the header and footer, they do not reduce the bandwidth or server load.
Introduction to XSLT - Page 2
Practical XML for the Web
Take it From the Top - Page 4
|