Introduction to XSL

In a nutshell: XSL is a W3C specification that describes a method for visually presenting XML documents.

This tutorial will cover:

XML Documents

Styling XML Documents

Do not smoke, eat or drink in this room.

CSS

With CSS one can associate properties to tags: refer to hamlet example

TITLE

Simple model: properties are associated to tags or attributes.

CSS lacks complex page layout, i18n properties, and the capability to perform complex styling operations. Like TOCs (not styling per se, but which should not be written by the author, but rather by the process that produces the actual document)

XSL is an alternative to CSS that allows greater control over the presentation of the XML data.

What can it do?

Who is it for?

Applications that require high-level quality formatting:

But is it not meant to be used where presentation is deeply tied to the contents (like graphic design).

Example I: Hamlet

  A room in the castle. Enter KING CLAUDIUS, QUEEN GERTRUDE, POLONIUS, OPHELIA, ROSENCRANTZ, and GUILDENSTERN And can you, by no drift of circumstance, Get from him why he puts on this confusion, Grating so harshly all his days of quiet With turbulent and dangerous lunacy?  .

This Example could be done in CSS, but the next two can't

Formatted for paper output (PDF), formatted for the Web (XHTML)

Example II: Mixed Writing Modes

mixed writing modes

Example III: database

Complex transforms, 2-key sorting (artist/year), grouping (by artist)

. Sundays, The Blind  (Various) The Glory of Gershwin Compilation  Kamen, Michael Brazil  .

Other Examples

How do they do that?

   A room in the castle.

The XSL Process(es)

XSL transformation and formatting

The result tree is an XML document in which the markup has information about how to display the document: what font to use, the size of a page, etc. This markup is called Formatting Objects (elements) and Properties (attributes). For example:

ACT III Scene 1: A room in the castle Enter KING CLAUDIUS, QUEEN GERTRUDE, POLONIUS, OPHELIA, ROSENCRANTZ, and GUILDENSTERN .
  A room in the castle. Enter KING CLAUDIUS, QUEEN GERTRUDE, POLONIUS, OPHELIA, ROSENCRANTZ, and GUILDENSTERN .

deliberately simplified. Note the automatic numbering.

Server-Side/Client-Side XSL

XSL and other W3C specs

XSL uses CSS properties to express formatting information, and uses the CSS inheritance model.

TITLE

XSL and SVG, MathML

Transformations: XSLT

XSLT is a transformation language originally designed to transform any XML document into another XML document containing formatting objects: pages, blocks, graphics, text, etc.

XSLT transformation from one XM

General-purpose XSLT

XSLT has evolved to become a general-purpose transformation language from XML to XML.

Many users use it to transform their own XML document type to HTML for viewing within a browser

Templates

A template says: "when you find this in the input file, then output this

meaning: when you read a tag named 'title' print a block start, continue the matching process for what's inside the and close the block

Note the use of namespaces to differentiate between formatting objects and transformation instructions. XSL defines both

So this will transform:

Hamlet
 Hamlet 

HTML can also be generated very simply in the template, using for instance instead of

means: apply other templates to contents.

Implicit rule: text is copied from input to output: a style sheet with no rules will only return the character data of the input.

XSLT statements

Allow navigation and iteration within the input document tree

"Play" to HTML

Very simple one-template example using the 'pull' method:

   The Tragedy of Hamlet, Prince of Denmark  

The Tragedy of Hamlet, Prince of Denmark

Elsinore. A platform beforethe castle.

BERNARDO

Who's there?

FRANCISCO

Nay, answer me: stand, and unfold yourself.

.

This uses the 'push' method where structure follows the input. Roughly there is one template for each tag type in the input

XPath

Formatting Objects basics

Tree of Formatting Objects

Pages

The Page Model

The area model

On the page will be layed out , that contain text, images and other areas. An area is a rectangle, with padding and border:

Area: border, padding and conte

Block/inline areas

The concept of relative orientation and writing-modes. Where CSS defines top, bottom, left, right, XSL adds before, after, start and end. Areas can be of type: block or inline. Blocks are stacked from the 'before' side to the 'after' side, inlines are stacked orthogonally.

Inline and block areas

Formatting Objects:

fo:layout-master-set fo:page-master fo:page-sequence
fo:block fo:inline fo:character
fo:page-number fo:external-graphics

Properties

 This is Helvetica 14pt text. This is Helvetica 28pt text. 

Example: Play to FO

The style sheet has the same structure as play2html, but HTML output is now FO. @@internationalisation of generated texr (Act, Scene) refer to DocBook

                             Table of Contents                                                Scene        - Act        Act       Act  p. "/>    Scene  p. "/>              

Top-level Template

For the sake of simplicity, we use one type of page, one size, no alternatives.

Page Format

Page Sequence Master

A sequence of a single page. We could have made 2 page-masters (odd and even) and used a alternating page sequence master

Page Sequence

Flow

Contains blocks, which contains text and inlines

I18N Formatting Objects and Properties

Apguru Exji 

Alignment Baselines

Horizontal and Vertical baselin

Other Formatting Objects

And Properties

Example: mixed writing modes

Go to Windows

If you are still interested.

Status of the specifications

Implementations

The Future