XSL Formatting Objects


XSL Formatting Objects

Zunächst für Online und Druck-Dokumente.

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

Formatierung durch areas (wie box in CSS) und spaces (Zwischenräume).

elementare Objekte:

Attribute angelehnt an CSS

 

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>

      <!-- 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.

Apache FOP

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

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 

einfaches Beispiel für XSLT nach XSL-FO (von den Apache FOP Beispielen):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
  <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
  <!-- ========================= -->
  <!-- root element: projectteam -->
  <!-- ========================= -->
  <xsl:template match="projectteam">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
          <fo:region-body/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="simpleA4">
        <fo:flow flow-name="xsl-region-body">
          <fo:block font-size="16pt" font-weight="bold" space-after="5mm">Project: <xsl:value-of select="projectname"/>
          </fo:block>
          <fo:block font-size="10pt">
            <fo:table table-layout="fixed">
              <fo:table-column column-width="4cm"/>
              <fo:table-column column-width="4cm"/>
              <fo:table-column column-width="5cm"/>
              <fo:table-body>
                <xsl:apply-templates/>
              </fo:table-body>
            </fo:table>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
  <!-- ========================= -->
  <!-- child element: member     -->
  <!-- ========================= -->
  <xsl:template match="member">
    <fo:table-row>
      <xsl:if test="function = 'lead'">
        <xsl:attribute name="font-weight">bold</xsl:attribute>
      </xsl:if>
      <fo:table-cell>
        <fo:block>
          <xsl:value-of select="name"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block>
          <xsl:value-of select="function"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block>
          <xsl:value-of select="email"/>
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
</xsl:stylesheet>

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

Heinz Kredel
Last modified: Wed Jun 11 09:39:26 CEST 2003