Languages

CSS & XSL

Why does W3C recommend two different style languages? Which one should you use? Basically, the rule can be summarized very succinctly:

Use CSS when you can, use XSL when you must.

Why

The reason is that CSS is much easier to use, easier to learn, thus easier to maintain and cheaper. There are WYSIWYG editors for CSS and in general there are more tools for CSS than for XSL. But CSS's simplicity means it has its limitations. Some things you cannot do with CSS, or with CSS alone. Then you need XSL, or at least the transformation part of XSL.

So what are the things you use XSL for? In general everything that needs transformations. For example, if you have a list and want it displayed in lexicographical order, or if words have to be replaced by other words, or if empty elements have to be replaced by text. CSS can do some text generation, but only for generating small things, such as numbers of section headers.

Diagram

Diagram of the role of XSL and CSS in rendering HTML and XML documents

This diagram shows the role of XSL and CSS. XML documents can be rendered in three different ways: (1) if the document doesn't have to be transformed, use CSS. Otherwise, use XSL-T, the transformation language of XSL, in one of two ways: either (2) generate the style properties together with the rearranged text, using a sub-language of XSL called XSL-FO (XSL Formatting Objects); or (3) generate a new XML or HTML document and provide a CSS style sheet for that new document.

More information

Bert Bos, style activity lead
Copyright © 1994–2022 W3C® Privacy policy

Created 22 July 1999.
Last updated Fri 01 Apr 2022 01:53:20 PM UTC

Languages

About the translations