4.1. Why Stylesheets?
The XML document and stylesheet are complementary. The document is the essence, or meaning, of the information, while the stylesheet describes the form it takes (see Figure 4.1). Think of applying a stylesheet to a document as preparing a meal from a cookbook. Your XML document is a bunch of raw, unprocessed ingredients; the stylesheet is a recipe, telling the chef how to handle each ingredient and how to combine them. The software that transmutes XML into another format, based on the stylesheet's instructions, is the chef in our analogy. After the dicing, mixing, and baking, we have something palatable and easily digested.
Figure 4.1. A stylesheet helps produce a formatted document
4.1.1. Encouraging Good Habits
Separating markup and style may seem like a hassle: HTML is very successful and doesn't require any stylesheets. Its elements have intrinsic presentational settings every web browser uses to create a good-looking page. But there are benefits of dividing the two:
Keeping style information out of the markup frees the author to concentrate on the meaning of the document without worrying about its appearance. In HTML, choosing which element to use is a decision of style as well as function. By using a stylesheet, you can keep the markup pure and focused without polluting it with appearance details.
Keeping style settings in a separate document makes ...
Get Learning XML now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.