cssxslt

Difference between XSL and CSS


Maybe this is a stupid question, but what is the difference between XSL and CSS? They are both styling sheets. When would you want to use one over the other. I looked around and saw that CSS is generally used before XSL when possible... but why?


Solution

  • Assuming you are talking about XSLT rather than "XSL" (the latter term should be avoided because it is used in different ways by different people):

    CSS provides a great deal of capability for rendering content. This capability is increasing all the time.

    XSLT focuses on transforming content.

    For example, you can write a report that groups, sorts, and summarizes data in XSLT, but you can't do so in CSS. Until recently CSS couldn't alter the content in any way, for example by rendering <cite>3</cite> as [3].

    You should use XSLT and CSS together. Use CSS for the pure rendering parts of the job, and XSLT for the transformation parts.

    With the availability of Saxon-CE [now SaxonJS] in the browser, you can also start to use XSLT for handling user interaction, such as responding to clicks by showing or hiding data: the kind of things you would otherwise have to do in Javascript.