Working XML: Fundamentals of Web publishing with XML
By Benoit Marchal2004-06-28
Fundamentals of Web publishing with XML
Through this column's discussion forum, various mailing lists, and my consulting activity, I have noticed a growing interest in managing and publishing Web sites with XML and XSL. Even though many developers are familiar with XML and XSL, building a coherent system is no small task. In this article, I walk you through a practical, step-by-step example of how to create Web sites in XML.
I will illustrate the technique with a tool developed through this column, the XM plug-in for Eclipse (see Resources). The information provided here is useful even if you use another publishing environment, such as Apache Cocoon, but I find XM to be more user-friendly.
Why XML and XSL?
First, I'll take a look at the benefits and costs of publishing with XML. You'll find more than one reason to turn to XML -- so many reasons, in fact, that I could not cover them all in this article. I only highlight the most frequently heard motivations:
It's simpler. You might not think so when you get started, since you need to learn so many new tools, but once you have an XML solution in place your site management chores will be dramatically reduced.
It's obsolescence-proof. XML separates the content (text and images) from the styling and the publishing, so you can change one independently from the other. For example, when you write new documents you concentrate on the writing and not on the colors, background, or navigation. Conversely, when you change the colors, background, or navigation, XML and XSL automatically update all your pages.
It's an open standard. XML is supported by many commercial and open-source tools. Even if a vendor disappears, discontinues a product, or doesn't support the features you need, you can be confident that there's a replacement.
It's easily adaptable. XML documents are like tiny databases, and the stylesheets are like scripts that query and manipulate the data from those document databases. These stylesheets are incredibly flexible -- from straightforward publishing to computing new content such as tables of contents, indices, and more.
But what about the cost? You have to balance the costs of writing the stylesheets against their benefits. It pays to automate repetitive tasks, but don't overdo it. If your site contains only a handful of pages, it is faster and cheaper to forgo XML. When the site reaches 10 to 20 pages, XML starts to pay for itself.
Personally, I like XML because it simplifies site management. Several years ago, I had to maintain a site that contained over 100 pages with a regular HTML editor. Believe me, that was no fun. Any change to the site, such as adding or removing sections, would take hours of copying and pasting links. Mistakes and broken links were frequent.
Not so with XML and XSL. Instead, stylesheets automate the boring, repetitive tasks, saving time and minimizing errors. Of course, XML is not the only solution. Some editors offer a template-based approach that is like a combination of XML and XSL. Still, I prefer XSL because it's a scripting language (limited only by my imagination) and it is not tied to proprietary solutions.
You can use stylesheets on the server, client, or webmaster desktop. The XM plug-in for Eclipse implements the webmaster desktop -- and when in batch mode, it also works on servers. The plug-in automatically creates a static Web site (such as a bunch of HTML pages) that are ready to upload to any server. By using stylesheets on the webmaster desktop, you can further increase XML's flexibility because -- unlike the alternatives -- it is compatible with every Web server and browser.
When to use dynamic content
While XML complements JSP, it does not compete with it. A typical Web site is 95 percent static content (such as FAQs, images, and descriptions), the rest is more dynamic (such as forums, search forms, or shopping carts). When it comes to static content, XML excels, whereas JSP is ideal for the more dynamic content.
To get the best of both worlds, I often generate JSP pages through XML and XSL. Again, the goal is to isolate the content from the publishing. To generate a JSP page instead of an HTML page with the XM plug-in, add the xr:extension="jsp" attribute to the xsl:output element.
What about servlets, JSP, PHP, or ASP? In other words, what about dynamically generated Web sites? Many shops have turned to dynamic hosting to gain the same benefits and simplify site maintenance. The code in the servlet or JSP page takes care of the presentation. How does this compare to XML and XSL?
In a nutshell, XML is more efficient. Dynamic sites tend to be slower because the server computes the page for every request. Those sites are also more difficult to set up and maintain, which unfortunately often translates into less stable sites. I know there are ways around all these problems, but you will find that XML delivers better results at a fraction of the cost.
Tutorial pages:
|
First published by IBM developerWorks
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "Working XML: Fundamentals of Web publishing with XML"
You must be logged in to post a comment.
Link to This Tutorial Page!

