Styling XML documents

Presentation of XML documents

Ideally, XML documents do not contain presentation markup. Tags and attributes should describe what the document is about, not how the document looks.

<PLAY>
<TITLE>The Tragedy of Hamlet, Prince of Denmark</TITLE>
  <ACT>
    <SCENE title="Elsinore. A platform before the castle.">
      <STAGEDIR>
        FRANCISCO at his post. Enter to him BERNARDO
      </STAGEDIR>
.
      <SPEECH speaker="BERNARDO">
        <LINE>Who's there?</LINE>
      </SPEECH>
.
      <SPEECH speaker="FRANCISCO">
        <LINE>
          Nay, answer me: stand, and unfold yourself.
        </LINE>
      </SPEECH>
.
      <SPEECH speaker="BERNARDO">
        <LINE>Long live the king!</LINE>
      </SPEECH>

...

can be presented as this.

CSS and XSL

Three Specifications

XSL process

In order to generate contents, XSL introduced a two-step process: (1) transformation of the original document into an intermediary format that contains the original and generated text, with markup describing formatting semantics, and (2) rendering of this format. Since it seemed convenient that that intermediary document should be expressed as XML, the transformation part was generalized to a AnyML to OtherML and became a separate document: XST Transformations (XSLT)

XSLT

XPath

Part of XSLT that allows access to the input XML documentNecessary for specifying which part of the source to retrieve and modify into the output

Examples:

<xsl:value-of select="ACT/SCENE/SPEECH/@speaker"/>

will return all speaker attributes nodes as a string: "BERNARDO FRANCISCO BERNARDO..."

or:

 /ACT[3]/SCENE[position() &lt; 3]/
 SPEECH[@speaker="Hamlet"]/LINE[substring(.,"beer")]

Points to Act V, Scene 1:

<SPEECH speaker="Hamlet">
<LINE>No, faith, not a jot; but to follow him thither with</LINE>
<LINE>modesty enough, and likelihood to lead it: as</LINE>
<LINE>thus: Alexander died, Alexander was buried,</LINE>
<LINE>Alexander returneth into dust; the dust is earth; of</LINE>
<LINE>earth we make loam; and why of that loam, whereto he</LINE>
<LINE>was converted, might they not stop a beer-barrel?</LINE>
<LINE>Imperious Caesar, dead and turn'd to clay,</LINE>
<LINE>Might stop a hole to keep the wind away:</LINE>
<LINE>O, that that earth, which kept the worldin awe,</LINE>
<LINE>Should patch a wall to expel the winter flaw!</LINE>

XPath could also be generalized and was therefore jointly designed by XSLT and XLink WGs

Formatting Objects

XSL process

An XML vocabulary for presentation semantics.

Example

<xsl:template match="TITLE">
  <fo:block font-family="Helvetica" 
            font-size="20pt"
            space-after.optimum="2em" 
            keep-with-next.within-page="always">
    <xsl:apply-templates/>
  </fo:block>
</xsl:templates

Elements and Attributes

Elements (formatting objects)

Attributes (properties)

XSL Processing

XSL process

Examples/Applications

Current Situation: XSLT 1.1

Current Situation: XSLT 2.0, XPath 2.0

Current Situation: XSL 1.0