These slides look best viewed using Opera in full screen mode (press F11).
They will be displayed as a multipage slideshow that can be
traversed using the page-down/page-up keys.
Printing XML
Why CSS is better than XSL
Michael Day
CEO, YesLogic Pty Ltd
mikeday@yeslogic.com
XTech 2005, Amsterdam
Thursday 26 May, 2005
Who am I
- Michael Day, mikeday@yeslogic.com
- CEO, YesLogic Pty Ltd
- Melbourne, Australia
- architect of Prince XML + CSS formatter
What is Prince
- XML + CSS → PDF
- XML: XHTML, DocBook, or whatever
- CSS: CSS 2.1 as used on web, also some CSS 3
- we support SVG and are working on MathML
What can Prince do
- this book!
- written in XHTML
- styled with CSS
- converted to PDF with Prince
- everything a book needs
- page headers/footers duplex layout, page numbers
- floats, tables, images
- table of contents with cross-references and leaders
Why am I here
- Why did we make Prince?
- Two beliefs:
- XML is a great way to represent documents
- CSS is a great way for styling XML for printing
- Prince is the result of these beliefs: printing XML with CSS
- not going to talk about first belief, take it as given
- second belief needs more explanation
Is CSS better than XSL?
- provocative topic, sounds somewhat confrontational
- overlap between two approaches, both attack similar problems
- CSS is more economical
- less time, less money, less stress
- if you can do it with CSS, you can probably do it with XSL
- more time, more expertise, more maintenance
- people tell us the CSS approach makes their life easier
Quick CSS intro
- rules, selectors, properties, values
- concise syntax, human readable and writable
CSS is easy to learn
- h1 { color: red }
- very low barrier to entry
- success on the web
Quick XSL intro
- XSL = XSLT + XSL-FO
- XSLT: XML scripting language for transforming XML documents
- XSL-FO: presentational markup
- XSL approach uses XSLT to transform documents into XSL-FO
XSL is a challenge to learn
- requires mastering two new XML vocabularies
- requires in-depth knowledge of XML data models
- "style sheets" are compound docs with three namespaces
- your input document namespace
- XSLT elements
- XSL-FO elements
- training issues
- so much to learn
- who will learn it? programmers? designers?
CSS is based on style rules
- property-level granularity
- allows arbitrary division / composition of style sheets
- promotes modularity
- saves typing by reducing duplication
- example:
- rules for fonts, colors, margins
- rules for headings, paragraphs, quotes
- flexibility in style sheet structure
CSS style rules are declarative
- declare the style you want, CSS makes it happen
- * { text-underline: none }
- *.legalese { text-transform: uppercase }
- h1 + p { font-size: 125% }
- a[href]::after { content: attr(href) }
- CSS rules are declarative
- they declare the desired style
- they make perfect sense in isolation
- CSS implementation is responsible for cascading process
XSL is based on element templates
- exactly one template matches each input element
- templates emit output elements/attributes
- default template copies text recursively
- element-level granularity
XSL templates are not declarative
- aha you say, XSL is declarative too!
- yes, but... everything is declarative
- question is, what level of abstraction?
- even assembly language is declarative
- XSL is declarative language for XML transformation
- XSL is not a declarative language for styling
Why is this a problem
- earlier examples cannot be done in XSL
- * { text-underline: none }
- requires modifying every template
- alternatively, implement second transform pass
- *.legalese { text-transform: uppercase }
- requires duplicating every template
- or adding if test or function call to every template
- alternatively, implement second transform pass
- h1 + p { font-size: 125% }
- a[href]::after { content: attr(href) }
- existing templates must be modified
What is XSLT
- XSLT is a programming language
- parameters, variables
- conditional logic
- recursive functions
- external scripts
- Turing complete
- XSLT is an XML scripting language
- equivalent of grep/awk/sed/perl for XML world
- handy for writing transforms and little XML utilities
- XSLT 2.0 reinforces this by adding features like typing
XSLT is unsuitable for styling
- XSLT is not a styling language!
- domain of XSLT is elements, attributes, templates and functions
- perl scripts that transform XML are not style sheets
- writing programs to format documents is suboptimal
- requiring programming impedes designers
- higher maintenance cost
- no separation of concerns: content manipulation and styling
XSLT is still useful
- publishing pipelines often need more than just styling
- small modular transforms
- generate table of contents, index, glossary
- sum invoice totals
- perform macro pre-processing: <logo/> → SVG
- many other processing steps:
- XInclude processing
- schema validation / augmentation
- database queries to fill in values
- XSLT has role to play as one tool among many
CSS is capable of printing
- page style
- page breaking
- page headers/footers
- page numbering
- named pages
- duplex printing
- cross-references
- leaders
CSS enables content repurposing
- CSS works across many media out of the box
- browsers on screens, presentations, printing, aural
- @media rules
- combine specific style sheets
- common.css
- screen.css
- print.css
Why not use CSS for printing
- CSS has had a huge impact on the web
- more styling possibilities
- cleaner markup
- greater range of dynamic applications
- focus on webpages means that printing is often neglected
- browsers concentrating on screen media
- continuous, not paged layout
- printing lags behind, even though CSS supports it
- duplicating web content for printing is a hassle
- CSS is good for printing, everyone knows it, why not use it?
CSS printing tools
- most tools that print don't do much CSS and vice versa
- browsers, html2ps, LaTeX converters
- Prince has first-class CSS support with emphasis on printing
- Prince 5.0 beta release last week
- PDF links/bookmarks/security
- support for wide range of UNICODE
- CSS positioning
- MacOS X support
- many other new features and improvements
The more the merrier
- we want to be the best out of a strong field
- we encourage XSL-FO formatters to support CSS
- then can truly say you support printing XML
- many of your users are frustrated, we hear them
- promote standard models for styling, printing
Final thought
- we believe that printing XML should be easy
- if you find it difficult, come and talk to us!
- Michael Day, mikeday@yeslogic.com
- Håkon Wium Lie, howcome@yeslogic.com
- http://yeslogic.com
- http://princexml.com