Printing in css is the new Grey.

Recently, I have been asked to look into printing with css at work. Luckily for me, right at that time came an article on alistapart called Printing a Book with CSS: Boom!. This made me set up an discussion at work, XSLT FO vs CSS, with me as an css advocate.

We (I currently work for a dutch goverment department) now use xslt and fo to print documents and I for one, believe that xlst is way to big to be used only for this. CSS is in my opinion a much better tool, as it is simpler to write and maintain. XSLT is the way to go if you actually Transform anything, but if you are going to print stuff of a webpage you don’t have to do this…

One disadvantage for xslt is the larger amount of code necessary for simple tasks. See this xsl example: <xsl :template match="html:p[@class='copyright' and ancestor::html:div[@class='head']]" priority="100"> <fo :block space-before="8pt" space-after="8pt" font-size="75%"> <xsl :apply-templates/> </fo>


And its css counterpart: div.head p.copyright { margin-top: 8pt; margin-bottom: 8pt; font-size: 75% }


Which is better, that depends on the goal you wish to achieve, I vote for css. I will keep you informed of what happens at work…

surely with support for things like page-break-after: always; css has a good chance.

Also see the site of the W3C for more information.