Introduction

A common problem when using XSLT to make HTML and CSS is keeping the XSLT, HTML and CSS synchronized. Changes to the XSLT that affect what HTML is generated necessitate corresponding changes to CSS; changes to the CSS may necessitate changes to the XSLT. Over time there will be some elements in the HTML for which there is no style information in the CSS, or for which the style information is out of date; there will be rules in the CSS that are no longer needed, or, worse, that are out of date and are only sometimes triggered.

Generating CSS from within XSLT, perhaps with one large xsl:text element, helps to reduce the divergence by making it easier to find CSS rules that affect a given element. But it is still easy to forget to update the CSS. A search for div.beer might not show up anything, but the CSS might have a selector fridge>* which matches beer (or any other element) when it's in the fridge. So it is not always trivial to locate the appropriate CSS rule to update.

With XSLT 3 also comes expand-text="yes" and curly braces being potentially special inside text node constructors, conflicting with CSS syntax.

CSS Within supports multiple stylesheets (for example for Web and PDF), and can run in pure XSLT or with extension instructions currently available for Saxon, in Java). Limited usage experience suggests that CSS Within makes HTML generation easier to maintain and more robust over time. This paper describes how to use CSS Within in your own projects and also discusses the current implementations and their limitations.