The Extensible Style Language (XSL)

The Extensible Style Language (XSL) is described in a recent submission to the W3C. It is a stylesheet language based on both Cascading Style Sheets (CSS) and the Document Style Semantics and Specification Language (DSSSL, ISO/IEC 10179:1996). XSL provides sophisticated formatting capabilities for both online and print applications.

XSL provides a superset of the functionality available in CSS. Additional features include:

  • Element reordering. XSL stylesheets can format elements independent of their order in the source document.

  • Powerful selection mechanism for source elements. It is possible to select elements based on ancestry/children, position, and uniqueness.

  • Generated text. XSL stylesheets can insert text and graphics into the formatted document.

  • Support for ECMAScript. User-defined ECMAScript functions can be included in the XSL stylesheet to evaluate the formatting characteristics of a document.

  • Extensibility. It will be possible to extend XSL to support new formatting applications.

Key Design Principles

  • XSL should be straightforwardly usable over the Internet

  • XSL should be expressed in XML syntax

  • XSL should provide a declarative language to do all common formatting tasks

  • XSL should provide access to a scripting language to accommodate more sophisticated formatting tasks

  • XSL stylesheets should be human-legible and reasonably clear

  • XSL stylesheets shall be easy to create

  • Terseness in XSL markup is of minimal importance

Stylesheet Structure

The heart of an XSL stylesheet is a collection of rules. Each rule contains a pattern and an action . Patterns locate elements within the source document, actions determine how these elements should be formatted.

Rules

A simple rule looks like this:

<rule>
  <target-element type="emphasis"/>

  <sequence font-posture="italic">
    <children/>
  </sequence>
</rule>

This rule makes the content of <emphasis> elements in the source document appear in italics in the formatted output.

Patterns

Patterns express the location of an element in the source document. The simplest pattern simply names the target element. More complex patterns can include ancestors and descendants of the target element along with specific attribute values and uniqueness constraints. For example, the following pattern will only match the first <para> of a <listitem> in an <itemizedlist>, and only if the list item has an override attribute with the value “ opencircle ”:

<element type="itemizedlist">
  <element type="listitem">
    <attribute name="override" value="opencircle"/>
    <target-element type="para" position="first-of-any"/>
  </element>
</element>

Additional pattern elements can detect the presence or absence of an attribute (without a specific value), select arbitrary elements and siblings, make selections based upon ID and CLASS and express importance and priority, as per CSS. There are also elements which match the root element of the document and provide a default action if no specific pattern matches. A conflict resolution mechanism is employed to assert that only a single pattern ever matches a given element.

Multiple actions for the same pattern can be introduced with modes. Modes allow a stylesheet to process the same elements in more than one context. This allows section titles to be rendered differently in a Table of Contents than they are in the body of the document, for example.

Actions

Actions are expressed using flow objects. Flow objects encapsulate the general nature of a formatted element—this is a paragraph, this is a rule, this is a table, etc. Characteristics attached to a flow object provide additional information about how the object is to be formatted (use an italic font, indent by a certain amount, etc.).

In the current proposal for XSL, there are two distinct kinds of flow objects, DSSSL flow objects and HTML flow objects.

The action portion of a rule describes the sequence of flow objects that should be generated when processing the selected element. Specifying the formatting of an element may involve producing not only a flow object for that element, but possibly flow objects for the children of that element or other arbitrary elements as well.

For example, here's an action that might be used for the first paragraph of a list item in an itemized list:

<paragraph
   first-line-start-indent="-10pt">

   <line-field
      field-width="10pt">
      <literal>&bull;</literal>
   </line-field>

   <children/>
</paragraph>

This action uses a hanging indent and a line field to produce a bullet before the paragraph.

Stylesheet Information

This poster provides only the briefest introduction to XSL. For more information, please consult the following resources:

http://www.w3.org/TR/NOTE-XSL-970910

The XSL Submission.

http://www.w3.org/TR/WD-CSS2/

The public Working Draft of CSS2.

http://www.oasis-open.org/cover/dsssl.html

Information about DSSSL

Poster Information

This poster was prepared by Norman Walsh of ArborText, Inc. The SGML source of the poster is an Article from the DocBook V3.0 DTD. It was written in Adept 7.0 and printed with a DSSSL stylesheet using Jade. The resulting 8½x11 pages were enlarged at a local copy shop.

An online version is available at http://nwalsh.com/docs/posters/sgml97/.

Norman Walsh, 
ArborText, Inc.
1000 Victors Way
Ann Arbor, MI 48104