Using XSL for Websites

Throughout the course of my web development learning, I've always had a central problem to deal with. On a typical website, multiple pages have some sort of general, non-changing bits that stay constant throughout the site: headers, footers, and navigational bars are great examples. The only piece that changes regularly, and is arguably the most important piece of a web page, is the central container. How do you keep these two pieces separate on both the frontend and backend of the site? Also, if there are non-changing or simple pieces of a website that do not change from page to page, is there a way to keep them on the client side to keep bandwidth low?

There are several options to this problem, the most obvious one being AJAX. When a user clicks on a new link, a request is sent for an XML document that would be parsed out and displayed within the container. The XML would be much smaller than an entire xHTML document and would be easy to setup and send from a server. It would be a truly clean separation of data v presentation. The main fall is with the URL - an AJAX request does not refresh the address bar. A user would have difficulty linking to a specific page from a browser, and search engine robots would only see a single address for an entire site. Non-Javascript users would need a separate system built for them, further complicating the website

If you work within a framework or templating system, you may work with caching systems to deal with this problem. Outside of this, the most viable solution is XSL, a language designed to parse out and present XML data. XSL can be used on the client or server side - when used on the client side, though, it unlocks a world of possibilities. Browsers treat XSL like a CSS document, downloading it and using it to interpret a document requested from a server.

XSL uses three main tools to read and parse XML. XSLT is a templating language that moves, resorts, and can do basic if/then statements to present XML. XPath can target a specific element or specific group of elements to be used by XSLT. XSL-FO reformats the individual pieces of an XML and can also move and resort a document. Combining these three tools can result in a powerful templating tool that exists on the client side, allowing the client's computer to do the processing and presentation of the website data.

There are few shortcomings to XSL. Some state that the learning curve is sharp, as the language is unique and difficult to easily peruse. Also, some browsers (IE7 and Firefox 2) have specific XSL capabilities that will override website XSL declarations. A good discussion of this problem and a work around can be found here: Besides these two problems, though, XSL does promise to be an excellent solution to a web developer with a templating problems and a love for XML.