XSL Formatting Objects


Einleitung

Darstellung von Online- und Druck-Dokumenten sowie Sprachausgabe.

Spezifikation der grundlegenden Elemente, ohne die Details einer Implementierung festzulegen.

für Seiten
Breite, Höhe, Ränder, Bereiche, Regionen
für Blöcke und Inline-Elemente
Breite, Höhe, Ränder
für Blöcke
Absätze, Listen, Tabellen, Bilder
für Inline-Elemente
Links (a), Font-Attribute
für Grafiken
Einbindung verschiedener Formate
für Sprachausgabe
wie in CSS2
für Internationalisierung
Unicode und Textschreibrichtungen: lr-tb, rl-tb und tb-rl.
XSL-FO Verarbeitungsprozess

Der XSL-FO Verarbeitungsprozess (Quelle W3C)

Der Verarbeitungsprozess verläuft intern durch verschiedene Verfeinerungen von fo:-Bäumen über object/property-Bäumen zu object/traits-Bäumen. Die Letzteren können dann direkt auf dem Ausgabemedium dargestellt werden.

3 Dinge bringt XSL-FO unter einen Hut:

Spezifikation der Darstellungselemente
fo:block, fo:inline mit Eigenschaften (properties), die CSS2 entsprechen.
Spezifikation der Charakteristika des Ausgabemediums
für die Druckausgabe (PDF) fo:layout-master-set, fo:simple-page-master fo:region-body oder ähnliche Dinge für Bildschirmausgabe oder Sprachausgabe
Beschreibung des (Inhalts)Flusses
wie "fliessen" die Inhaltselemente in das Ausgabemedium: fo:page-sequence master-reference="seite", fo:static-content, fo:flow flow-name="body"

XSL Formatting Objects Sprachelemente

Als Namensraum wird in diesem Abschnitt immer fo: mit dem URL http://www.w3.org/1999/XSL/Format verwendet. Das Root-Element ist immer fo:root.

elementare Darstellungen:

Formatierung durch areas, die eine Erweiterung des Box-Modells von CSS (block oder inline) sind. U.A. können auch Zwischenräume spaces genauer definiert werden sowie Nebenbedingungen (constraints) für die Anordnung der Areas.

XSL-FO Area Rechtecke

XSL-FO Area Rechtecke (Quelle W3C)

Attribute/Properties angelehnt an CSS2

Die CSS2 Atribute sind zum Teil weiter ausdifferenziert.

Definition der Charakteristika des Ausgabemediums

Hier nur für Druck/PDF-Ausgabe betrachtet.

Die Definitionen umfassen im Wesentlichen die Breite und Höhe, sowie die verschiedenen Ränder.

XSL-FO Seitenbereiche

XSL-FO Seitenbereiche (Quelle W3C)

Beschreibung der Füllung (flow)

Wie werden die Darstellungselemente (z.B. fo:block) in die Ausgaberegionen eingefüllt, bzw. wie fliessen diese in die Ausgaberegionen?

Einfaches Beispiel

von den Apache FOP Beispielen:

<?xml version="1.0" encoding="utf-8"?>

<!-- example for a simple fo file. At the beginning the page layout is set. 
  Below fo:root there is always 
- a single fo:layout-master-set which defines one or more page layouts
- an optional fo:declarations 
- and a sequence of one or more fo:page-sequences containing the text and formatting instructions 
-->

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <fo:layout-master-set>
  <!-- fo:layout-master-set defines in its children the page layout: 
       the pagination and layout specifications
      - page-masters: have the role of describing the 
            intended subdivisions of a page and the geometry 
            of these subdivisions 
        In this case there is only a simple-page-master which 
        defines the layout for all pages of the text
  -->
    <!-- layout information -->
    <fo:simple-page-master master-name="simple"
                  page-height="29.7cm" 
                  page-width="21cm"
                  margin-top="1cm" 
                  margin-bottom="2cm" 
                  margin-left="2.5cm" 
                  margin-right="2.5cm">
      <fo:region-body margin-top="3cm" margin-bottom="1.5cm"/>
      <fo:region-before extent="3cm"/>
      <fo:region-after extent="1.5cm"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <!-- end: defines page layout -->


  <!-- start page-sequence
       here comes the text (contained in flow objects)
       the page-sequence can contain different fo:flows 
       the attribute value of master-name refers to the page layout
       which is to be used to layout the text contained in this
       page-sequence-->
  <fo:page-sequence master-reference="simple">

      <!-- start fo:flow
           each flow is targeted 
           at one (and only one) of the following:
           xsl-region-body (usually: normal text)
           xsl-region-before (usually: header)
           xsl-region-after  (usually: footer)
           xsl-region-start  (usually: left margin) 
           xsl-region-end    (usually: right margin)
           ['usually' applies here to languages with left-right 
            and top-down writing direction like English]
           in this case there is only one target: xsl-region-body
        -->
    <fo:flow flow-name="xsl-region-body">

      <!-- each paragraph is encapsulated in a block element
           the attributes of the block define
           font-family and size, line-heigth etc. -->

      <!-- this defines a title -->
      <fo:block font-size="18pt" 
            font-family="sans-serif" 
            line-height="24pt"
            space-after.optimum="15pt"
            background-color="blue"
            color="white"
            text-align="center"
            padding-top="3pt">
        Extensible Markup Language (XML) 1.0
      </fo:block>


      <!-- this defines normal text -->
      <fo:block font-size="12pt" 
                font-family="sans-serif" 
                line-height="15pt"
                space-after.optimum="3pt"
                text-align="justify">
        The Extensible Markup Language (XML) is a subset of 
        SGML that is completely described in this document. 
        Its goal is to enable generic SGML to be served, 
        received, and processed on the Web in the way  
        that is now possible with HTML. XML has been designed 
        for ease of implementation and for interoperability 
        with both SGML and HTML.
      </fo:block>
      ...
    </fo:flow> <!-- closes the flow element-->
  </fo:page-sequence> <!-- closes the page-sequence -->
</fo:root>

Ergebnis als PDF.


XHTML nach FO nach PDF

Es existieren verschiedene Softwarepakete, die XSL-FO verarbeiten können.

Apache Formatting Objects Processor (FOP)

Bietet Konversion von XSL-FO Dateien nach PDF. Kann auch den Vorbereitungsschritt mit XSLT nach XSL-FO mit übernehmen.

Apache FOP

Apache FOP AWT-Vorschau

Optionen:

./fop.sh 

USAGE
Fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-pcl|-ps|-txt|-
at|-print] <outfile>
 [OPTIONS]  
  -d          debug mode   
  -x          dump configuration settings  
  -q          quiet mode  
  -c cfg.xml  use additional configuration file cfg.xml
  -l lang     the language to use for user information 
  -s          for area tree XML, down to block areas only

 [INPUT]  
  infile            xsl:fo input file (the same as the next) 
  -fo  infile       xsl:fo input file  
  -xml infile       xml input file, must be used together with -xsl 
  -xsl stylesheet   xslt stylesheet 
 
 [OUTPUT] 
  outfile           input will be rendered as pdf file into outfile 
  -pdf outfile      input will be rendered as pdf file (outfile req'd) 
  -awt              input will be displayed on screen 
  -mif outfile      input will be rendered as mif file (outfile req'd)
  -pcl outfile      input will be rendered as pcl file (outfile req'd) 
  -ps outfile       input will be rendered as PostScript file (outfile req'd) 
  -txt outfile      input will be rendered as text file (outfile req'd) 
    -txt.encoding encoding  use the encoding for the output file.
                    the encoding must be a valid java encoding.
  -svg outfile      input will be rendered as an svg slides file (outfile req'd) 
  -at outfile       representation of area tree as XML (outfile req'd) 
  -print            input file will be rendered and sent to the printer 
                    see options with "-print help" 

 [Examples]
  Fop foo.fo foo.pdf 
  Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)
  Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf
  Fop foo.fo -mif foo.mif
  Fop foo.fo -print or Fop -print foo.fo 
  Fop foo.fo -awt 

Die Vorlesung als PDF

Ein Beispiel für die Transformation von XHTML nach XSL-FO für den FO-Processor FOP von Apache.org.

Eine Alternative mit mehr Funktionen bietet der Antennahouse XSL Formater AXF.

Die Haupttexte der Vorlesung als PDF.


© Universität Mannheim, Rechenzentrum, 1998-2004.

Heinz Kredel

Last modified: Sun May 23 16:50:37 CEST 2004