UP PREVIOUS NEXT   Technologies Internet et Education, © TECFA
  3. Principes de base XSL/FO

3. Principes de base XSL/FO

Spécification de XSL
But
Usage

(FO est du XML avec XSL/FO mélange)

Statut

3.1 Organisation d'une "page" FO

Exemple 3-1: Un simple stylesheet XSLT + FO

A. Source XML

<page>
 <title>Hello Apache/FOP and Apache/Cocoon friends</title>
<content>
Here is some content. It should work with FOP 0.18 (and hopefully above).
It is totally uninteresting. It is totally uninteresting. ... </content> 
 
<content>
Here is some more content.
It is slightly uninteresting.  .... :)
</content> 
 
 <comment>Written by DKS/Tecfa 6/01</comment>
</page>

B. Feuille de style XSL/FO

<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0" >
 
<!-- rule for the whole document: root element is page -->
 
<xsl:template match="page">
 <fo:root>
  <fo:layout-master-set>
 
  <!-- Definition of a single master page. It is simple (no headers etc.) -->
  <fo:simple-page-master 
			 master-name="first
" 
			 margin-left="2cm"  margin-right="2cm"
			 margin-bottom="0.5cm" margin-top="0.75cm"
			 page-width="21cm" page-height="29.7cm"
			 >
   <!-- required element body -->
   <fo:region-body/>
  </fo:simple-page-master>
 </fo:layout-master-set>
  
 <!-- Definition of a page sequence -->
 <fo:page-sequence 
master-name="first">
  <fo:flow 
flow-name="xsl-region-body"
 font-size="14pt" line-height="14pt">
    <xsl:apply-templates/>
  </fo:flow>  
 </fo:page-sequence> 
</fo:root>
</xsl:template>
 
<!-- A series of XSLT rules that produce fo:blocks to be inserted above -->
 
 <xsl:template match="page/title">
    <fo:block font-size="36pt" text-align="center" line-height="40pt" space-before="0.5cm" space-after="1.0cm">
    <xsl:apply-templates/></fo:block>
  </xsl:template>
 
 <xsl:template match="content">
    <fo:block text-align="justify"  space-before="0.5cm">
    <xsl:apply-templates/></fo:block>
  </xsl:template>
 
 <xsl:template match="comment">
    <fo:block font-size="12pt" text-align="start" space-before="0.7cm" font-style="italic">
    <xsl:apply-templates/></fo:block>
  </xsl:template>
 
</xsl:stylesheet>

C. Sequelette XSL-T/FO de base

<xsl:template match="page">
 <fo:root>
  <fo:layout-master-set>
 
  <!-- Definition of a single master page. It is simple (no headers etc.) -->
  <fo:simple-page-master 
			 master-name="first
"  >
   <!-- required element body -->
   <fo:region-body/>
  </fo:simple-page-master>
 </fo:layout-master-set>
  
 <!-- Definition of a page sequence -->
 <fo:page-sequence 
master-name="first">
  <fo:flow 
flow-name="xsl-region-body"
 font-size="14pt" line-height="14pt">
    <xsl:apply-templates/>
  </fo:flow>  
 </fo:page-sequence> 
</fo:root>
</xsl:template>
 
 
Architecture de la racine FO,

Sous la racine fo:root il y a toujours:

  • un fo:layout-master-set qui définit un ou plusieurs page layouts définis avec fo:simple-page-master
  • des déclarations à option fo:declarations
  • une sequénce d'un ou plusieurs fo:page-sequences qui contiennent du texte (litéralement ou fournis par XSLT) et des instructions de formattage.

UP PREVIOUS NEXT -- TIE