Transcript
Page 1: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

11

XSL FO Extensible Stylesheet XSL FO Extensible Stylesheet Language Formatting ObjectsLanguage Formatting Objects

• An advanced style language for XML An advanced style language for XML documents:documents:1.1. Language for transforming XML documents: XSLT Language for transforming XML documents: XSLT

2.2. XML vocabulary (of formatting objects) for XML vocabulary (of formatting objects) for specifying formatting semantics: specifying formatting semantics: XSL version 1.0, W3C Rec. (15 October, 2001)XSL version 1.0, W3C Rec. (15 October, 2001)

• 1 Introduction and Overview1 Introduction and Overview

• 2 Using XSL Formatting Objects2 Using XSL Formatting Objects

Page 2: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

22

What is it?What is it?• An XSL style sheet specifies the presentation An XSL style sheet specifies the presentation

of a class of XML documentsof a class of XML documents– by describing an XSLT transformation of the XML by describing an XSLT transformation of the XML

document into an XML document that uses the document into an XML document that uses the formatting vocabulary formatting vocabulary • XSL FO: a markup language to describe formatting XSL FO: a markup language to describe formatting

• XSL builds on CSS2 and DSSSLXSL builds on CSS2 and DSSSL – DSSSL a standardised but mainly unimplemented DSSSL a standardised but mainly unimplemented

SGML style languageSGML style language

Page 3: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

33

Example of XSL syntaxExample of XSL syntax• Formatting paragraph elements (p):Formatting paragraph elements (p):

<?xml version='1.0'?><?xml version='1.0'?><xsl:stylesheet version='1.0' <xsl:stylesheet version='1.0'

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xmlns:fo="http://www.w3.org/1999/XSL/Format"fo="http://www.w3.org/1999/XSL/Format" > ><xsl:template match="p"><xsl:template match="p"> <fo:block><fo:block> <fo:initial-property-set <fo:initial-property-set

font-variant="small-caps"/>font-variant="small-caps"/> <xsl:apply-templates/><xsl:apply-templates/> </fo:block></fo:block></xsl:template></xsl:template></xsl:stylesheet></xsl:stylesheet>

Page 4: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

44

1 Overview of XSL Formatting1 Overview of XSL Formatting

• A A style sheet processorstyle sheet processor accepts an XML accepts an XML document and an XSL style sheet, and document and an XSL style sheet, and produces a formatted presentationproduces a formatted presentation

• Two steps:Two steps:1. tree transformation: 1. tree transformation:

XML XML source treesource tree -> -> result treeresult tree (using XSLT) (using XSLT)2. formatting2. formatting

• interpreting the result tree to produce formatted interpreting the result tree to produce formatted presentationpresentation

Page 5: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

55

Transformation & FormattingTransformation & Formatting

Page 6: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

66

Basis of formattingBasis of formatting• Tree transformation adds information Tree transformation adds information

needed to format the result treeneeded to format the result tree• Formatting semantics expressed using a Formatting semantics expressed using a

formatting vocabularyformatting vocabulary, of, of– formatting objects formatting objects ((FOFOs)s),, nodes of the result nodes of the result

treetree• for typographic abstractions like page-sequence, for typographic abstractions like page-sequence,

block, in-line text, page reference, …block, in-line text, page reference, …•XSL 1.0 defines 56 formatting object classesXSL 1.0 defines 56 formatting object classes

– formatting propertiesformatting properties control the presentation control the presentation of formatting objects (indents, spacing, fonts, …)of formatting objects (indents, spacing, fonts, …)•XSL 1.0 defines 246 formatting properties; XSL 1.0 defines 246 formatting properties;

many common with CSS2many common with CSS2

Page 7: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

77

FormattingFormatting

• Formatting-object tree interpreted to produce Formatting-object tree interpreted to produce the representationthe representation

• Each FO specifies a part of pagination, layout Each FO specifies a part of pagination, layout and styling applied to its contentand styling applied to its content

• Properties control the formatting of a FOProperties control the formatting of a FO– some directly, e.g., colorsome directly, e.g., color– some through constraints, e.g., space-some through constraints, e.g., space-

before.minimumbefore.minimum-> rendered form not uniquely defined by XSL-> rendered form not uniquely defined by XSL

Page 8: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

88

Areas and Area TreeAreas and Area Tree

• Formatting generates an Formatting generates an area treearea tree consisting consisting of nested rectangular areasof nested rectangular areas– inline areasinline areas (e.g. glyph areas) within (e.g. glyph areas) within line areasline areas– lines within lines within block areasblock areas– blocks within blocks within regionsregions of a page of a page

• RenderingRendering causes the area tree to appear on causes the area tree to appear on a mediuma medium– areas printed on a sequence of sheets areas printed on a sequence of sheets

(or displayed on a single scroll in a browser)(or displayed on a single scroll in a browser)

Page 9: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

99

Generating the Area Tree (1/3)Generating the Area Tree (1/3)

• Formatting a gradual and complex processFormatting a gradual and complex process• Conceptual process of XSL formatting:Conceptual process of XSL formatting:• Element and attribute treeElement and attribute tree

– target of transformation, source of formattingtarget of transformation, source of formatting– consists of consists of element, attribute,element, attribute, and and text nodestext nodes– transformed into a … transformed into a …

• Formatting object treeFormatting object tree– consists of formatting consists of formatting objectsobjects with with propertiesproperties– more detailed: each character its own objectmore detailed: each character its own object

Page 10: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1010

Generating the Area Tree (2/3)Generating the Area Tree (2/3)

Page 11: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1111

Generating the Area Tree (3/3)Generating the Area Tree (3/3)

• Properties of the formatting object tree refined into Properties of the formatting object tree refined into traitstraits– e.g., by propagating inherited properties, and computing e.g., by propagating inherited properties, and computing

absolute values for relative propertiesabsolute values for relative properties• e.g., properties e.g., properties

font-size="12pt", start-indent="2em" font-size="12pt", start-indent="2em" become traits become traits font-size="12pt", start-indent="24pt" font-size="12pt", start-indent="24pt"

– traits control generation of areas out of formatting objectstraits control generation of areas out of formatting objects– some traits only available as a result of formatting, e.g., some traits only available as a result of formatting, e.g.,

page numbers page numbers

Page 12: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1212

Benefits of XSLBenefits of XSL

• an extensive model and vocabulary for an extensive model and vocabulary for expressing XML style sheetsexpressing XML style sheets

• pagination and layout model extend existing ones pagination and layout model extend existing ones – area model a superset of the CSS2 box modelarea model a superset of the CSS2 box model

• e.g., different writing directions; footnotes, page number refs.e.g., different writing directions; footnotes, page number refs.

• support of non-western-language directionssupport of non-western-language directions– distances specified in terms of distances specified in terms of before, after, startbefore, after, start

and and endend, relative to “writing-mode”, relative to “writing-mode”

• powerful source selection and manipulation powerful source selection and manipulation (with XPath/XSLT)(with XPath/XSLT)

Page 13: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1313

XSL Area ModelXSL Area Model

• Formatting objects generate Formatting objects generate areasareas– each 0 or moreeach 0 or more

•page breaks -> additional block areaspage breaks -> additional block areas

• line breaks -> additional line areasline breaks -> additional line areas

• Each area tree node (except root) is associated Each area tree node (except root) is associated to a rectangular portion of the output mediumto a rectangular portion of the output medium

• An area has a An area has a content-rectanglecontent-rectangle– portion for child areasportion for child areas– optionally surrounded by a optionally surrounded by a borderborder and and paddingpadding

Page 14: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1414

Content, Padding and BorderContent, Padding and Border

For For compatibility compatibility also CSS-like also CSS-like margins margins margin-top, margin-top, -right, -right, -bottom and -bottom and -left -left

space-beforespace-before

space-afterspace-after

start-start-

indentindent

end-indentend-indent

Page 15: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1515

Two area typesTwo area types

• block-areasblock-areas– generated in generated in block-progression-directionblock-progression-direction

(normally top-to-bottom)(normally top-to-bottom)– paragraphs and titles normally rendered using paragraphs and titles normally rendered using

fo:block, which creates block areasfo:block, which creates block areas– line-arealine-area a special case: no borders or padding a special case: no borders or padding

• inline-areasinline-areas– generated in generated in inline-progression-directioninline-progression-direction

(normally left-to-right)(normally left-to-right)– characters rendered using fo:character, which characters rendered using fo:character, which

generatesgenerates glyph-area glyph-area inline-areasinline-areas•no child areas, a single glyph image as contentno child areas, a single glyph image as content

Page 16: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1616

Formatting objects and Formatting objects and propertiesproperties

• XSL 1.0 defines 56 formatting objects XSL 1.0 defines 56 formatting objects … … page-sequence, simple-page-master, block, inline, page-sequence, simple-page-master, block, inline,

list-block, list-item, list-item-label, list-item-body, list-block, list-item, list-item-label, list-item-body, external-graphic, basic-link, float, footnote, ...external-graphic, basic-link, float, footnote, ...

• and 246 propertiesand 246 properties master-referencemaster-reference, , background-color, font-family, background-color, font-family,

font-size, space-before, end-indent, text-align, text-font-size, space-before, end-indent, text-align, text-indent, … indent, …

– many common with CSS2many common with CSS2

Page 17: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1717

Some central formatting objects Some central formatting objects 1/31/3

• fo:rootfo:root– top node of the formatting object treetop node of the formatting object tree– a wrapper for all the rest a wrapper for all the rest

• fo:simple-page-masterfo:simple-page-master– used as a template for creating pagesused as a template for creating pages– specifies the geometry of pagesspecifies the geometry of pages

•region-body (for page content)region-body (for page content)•region-before, region-after, region-start and region-before, region-after, region-start and

region-end region-end (for header, footer, and left and right sidebar)(for header, footer, and left and right sidebar)

Page 18: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1818

Page regionsPage regions• A simple page can contain 1-5 regions, specified A simple page can contain 1-5 regions, specified

by child elements of the by child elements of the simple-page-mastersimple-page-master

Page 19: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

1919

Top-level formatting objectsTop-level formatting objects• Slightly simplified:Slightly simplified: fo:rootfo:root

fo:layout-master-setfo:layout-master-set

(fo:simple-page-master | fo:page-sequence-master)+(fo:simple-page-master | fo:page-sequence-master)+

fo:page-sequence+fo:page-sequence+

fo:region-fo:region-bodybody

fo:region-fo:region-before?before? fo:region-fo:region-

end?end?

fo:region-fo:region-start?start?

fo:region-fo:region-after?after? specify masters specify masters

for page sequences for page sequences by referring to by referring to simple-page-masterssimple-page-masters

contents of contents of pagespages

Page 20: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2020

Some central formatting objects Some central formatting objects 2/32/3

• fo:page-sequencefo:page-sequence– specifies the creation of page sequencesspecifies the creation of page sequences– possibly different page-sequence (and page-possibly different page-sequence (and page-

sequence-master) for, say, each chaptersequence-master) for, say, each chapter

• fo:flowfo:flow– child objects of page-sequenceschild objects of page-sequences– flows attached to regions of a page-masterflows attached to regions of a page-master– content of flows distributes to regions of pagescontent of flows distributes to regions of pages

• No ‘page’-formatting objectsNo ‘page’-formatting objects– pages created by the formatterpages created by the formatter

Page 21: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2121

Content objects for pagesContent objects for pages

fo:static-content*fo:static-content*

Block-level object+Block-level object+

fo:page-sequence+fo:page-sequence+

fo:flowfo:flow

Block-level object+Block-level object+

Page 22: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2222

Some central formatting objects Some central formatting objects 3/33/3

• fo:blockfo:block– commonly used for paragraphs, titles, …commonly used for paragraphs, titles, …– may contain text, other blocks, ormay contain text, other blocks, or

• fo:inline fo:inline (to change properties, e.g., font-style of inline text)(to change properties, e.g., font-style of inline text)

• fo:table fo:table for formatting tabular materialfor formatting tabular material

• fo:list-block fo:list-block to format lists of to format lists of – fo:list-items offo:list-items of

• fo:list-item-label and fo:list-item-bodyfo:list-item-label and fo:list-item-body

Page 23: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2323

““Hello world” result tree as XSL Hello world” result tree as XSL documentdocument<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set><fo:layout-master-set> <fo:simple-page-master master-name="<fo:simple-page-master master-name="pagepage">"> <fo:region-body/><fo:region-body/> </fo:simple-page-master></fo:simple-page-master> </fo:layout-master-set></fo:layout-master-set> <fo:page-sequence <fo:page-sequence

master-reference="master-reference="pagepage"> <!--use 'page' master-->"> <!--use 'page' master--> <fo:flow flow-name=”xsl-region-body"><fo:flow flow-name=”xsl-region-body"> <fo:block>Hello World</fo:block><fo:block>Hello World</fo:block> </fo:flow></fo:flow> </fo:page-sequence></fo:page-sequence></fo:root></fo:root>

Page 24: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2424

Implementations?Implementations?

• W3C XSL Recommendation rather recentW3C XSL Recommendation rather recent

• What is the state of implementations?What is the state of implementations?

• Some promising/interesting ones:Some promising/interesting ones:– XEP by RenderXXEP by RenderX

• Java-based XSL-FO to PS/PDF Java-based XSL-FO to PS/PDF formatterformatter

• commercial (commercial ( $5000, April 2001); evaluation version free $5000, April 2001); evaluation version free

– Passive TeXPassive TeX• set of TeX macros to process XSL-FO by Sebastian Rahtzset of TeX macros to process XSL-FO by Sebastian Rahtz

– Apache FOPApache FOP

Page 25: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2525

Apache FOPApache FOP

• FOP (Formatting object to PDF) by J. TauberFOP (Formatting object to PDF) by J. Tauber• ““fop: a man who pays too much attention to his appearance”fop: a man who pays too much attention to his appearance”

– donated to XML Apache project donated to XML Apache project (http://xml.apache.org/fop/)(http://xml.apache.org/fop/)

– open-source freewareopen-source freeware– Java-based XML/XSL-FO to PDF (or MIF/PCL/TXT/...) Java-based XML/XSL-FO to PDF (or MIF/PCL/TXT/...)

processorprocessor

• Implements a useful subset of XSL 1.0 Rec;Implements a useful subset of XSL 1.0 Rec; Version 0.20.3: Version 0.20.3: – 41 formatting objects (out of 56) 41 formatting objects (out of 56) – 111 formatting properties (out of 246, or 228 w.o. 111 formatting properties (out of 246, or 228 w.o.

aural)aural)

Page 26: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2626

2 An XSL-FO Example2 An XSL-FO Example

• XSL FOs for a version of a handbook of XSL FOs for a version of a handbook of SpanishSpanish

• Overall structure of fo:root: specification Overall structure of fo:root: specification ofof– page masters, followed bypage masters, followed by– the content of the pagesthe content of the pages

Page 27: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2727

Example: Page dimensions and Example: Page dimensions and marginsmargins

<fo:layout-master-set><fo:layout-master-set> <fo:<fo:simple-page-mastersimple-page-master master-name="cover" master-name="cover" page-height="12cm"page-height="12cm" page-width="12cm"page-width="12cm" margin-top="0.5cm"margin-top="0.5cm" margin-bottom="0.5cm"margin-bottom="0.5cm" margin-left="1cm"margin-left="1cm" margin-right="0.5cm">margin-right="0.5cm"> </fo:</fo:simple-page-mastersimple-page-master>> … … </fo:layout-master-set></fo:layout-master-set>• plus similar simple-page-masters with plus similar simple-page-masters with

– master-name="rightPage" (identical)master-name="rightPage" (identical)– master-name="leftPage" (left and right margins switched)master-name="leftPage" (left and right margins switched)

Page 28: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2828

Intended layout of pagesIntended layout of pages

Page 29: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

2929

Page regionsPage regions• A simple page can contain 1-5 regions, specified A simple page can contain 1-5 regions, specified

by child elements of the by child elements of the simple-page-mastersimple-page-master

• Let us refine the page masters by specifying regionsLet us refine the page masters by specifying regions

Page 30: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3030

Example: Region dimensionsExample: Region dimensions <fo:simple-page-master master-name="cover"<fo:simple-page-master master-name="cover" … … dimensions and margins as above … >dimensions and margins as above … >

<fo:region-body margin-top="3cm" /><fo:region-body margin-top="3cm" /> </fo:simple-page-master> </fo:simple-page-master>

<fo:simple-page-master master-name="leftPage" … ><fo:simple-page-master master-name="leftPage" … ><fo:region-before extent="1cm"/> <fo:region-before extent="1cm"/> <fo:region-after extent="1cm"/> <fo:region-after extent="1cm"/> <fo:region-body <fo:region-body margin-top="1.1cm" margin-bottom="1.1cm" /> margin-top="1.1cm" margin-bottom="1.1cm" />

</fo:simple-page-master></fo:simple-page-master>

<!-- and "rightPage"<!-- and "rightPage" similarly … -->similarly … -->

• body uses all space inside page marginsbody uses all space inside page margins-> margins of region-body have to accommodate other regions-> margins of region-body have to accommodate other regions

Page 31: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3131

Example: Page SequencesExample: Page Sequences• Next: masters for Next: masters for sequencessequences of content pages, using of content pages, using

the defined simple-page-mastersthe defined simple-page-masters– repeatedly alternate masters for left and right pages:repeatedly alternate masters for left and right pages:

<fo:<fo:page-sequence-masterpage-sequence-master master-name="contents"> master-name="contents"> <fo:repeatable-page-master-alternatives> <fo:repeatable-page-master-alternatives>

<fo:conditional-page-master-reference <fo:conditional-page-master-reference master-reference="leftPage" master-reference="leftPage"

odd-or-even="even"/>odd-or-even="even"/> <fo:conditional-page-master-reference <fo:conditional-page-master-reference master-reference ="rightPage" master-reference ="rightPage"

odd-or-even="odd"/>odd-or-even="odd"/> </fo:repeatable-page-master-alternatives> </fo:repeatable-page-master-alternatives> </fo:</fo:page-sequence-masterpage-sequence-master>>

Page 32: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3232

Page SequencesPage Sequences

• Other attributes of conditional-page-master-reference Other attributes of conditional-page-master-reference to select the page master to be used:to select the page master to be used:– page-position="first" page-position="first"

• or "last", or "rest" (neither first or last), or "any"or "last", or "rest" (neither first or last), or "any"

– blank-or-not-blank="blank"/"not-blank"blank-or-not-blank="blank"/"not-blank"• for example, to generate a blank page to force chapters to for example, to generate a blank page to force chapters to

end at even-numbered pagesend at even-numbered pages

• Next: Specifying the sequences of content Next: Specifying the sequences of content pagespages– by naming masters to be used, and attaching by naming masters to be used, and attaching

content flows to regionscontent flows to regions

Page 33: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3333

Example: Contents of the Cover Example: Contents of the Cover PagePage <fo:<fo:page-sequencepage-sequence master-reference="cover"> master-reference="cover">

<fo:flow flow-name="xsl-region-body"> <fo:flow flow-name="xsl-region-body"> <fo:block font-family="Helvetica" <fo:block font-family="Helvetica"

font-size="18pt" text-align="end">font-size="18pt" text-align="end"> Spanish Review Handbook </fo:block> Spanish Review Handbook </fo:block>

<fo:block font-family="Helvetica" <fo:block font-family="Helvetica" font-size="12pt" text-align="end" font-size="12pt" text-align="end"

space-after="36pt">Copyright &#169; space-after="36pt">Copyright &#169; 2001 J. David Eisenberg</fo:block>2001 J. David Eisenberg</fo:block>

<fo:block text-align="end"> <fo:block text-align="end">A Catcode Production </fo:block> A Catcode Production </fo:block>

</fo:flow> </fo:flow> </fo:</fo:page-sequencepage-sequence> >

Page 34: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3434

Example: Cover Page Example: Cover Page FormattedFormatted

• Formatting the first page-sequence gives ... Formatting the first page-sequence gives ...

Page 35: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3535

Example: Content PagesExample: Content Pages

• Finally, a page-sequence for content pagesFinally, a page-sequence for content pages– with static-content for the header and footer, and with static-content for the header and footer, and

a flow for page bodies:a flow for page bodies:<fo:page-sequence master-reference="contents" <fo:page-sequence master-reference="contents"

initial-page-number="2">initial-page-number="2">

<!-- Content of page headers: --><!-- Content of page headers: --><fo:<fo:static-contentstatic-content flow-name="xsl-region-before"> flow-name="xsl-region-before"> <fo:block font-family="Helvetica" <fo:block font-family="Helvetica" font-size="10pt" text-align="center">font-size="10pt" text-align="center">

Spanish Review Handbook </fo:block> </fo:Spanish Review Handbook </fo:block> </fo:static-static-contentcontent>>

Page 36: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3636

Example: Content Pages Example: Content Pages ContinueContinue• Content for page footers:Content for page footers:

<!-- static-content is repeated on every page --><!-- static-content is repeated on every page -->

<fo:static-content flow-name="xsl-region-after"> <fo:static-content flow-name="xsl-region-after"> <fo:block font-family="Helvetica" <fo:block font-family="Helvetica" font-size="10pt" text-align="center">font-size="10pt" text-align="center"> P&#225;gina P&#225;gina <fo:page-number /><fo:page-number /> </fo:block> </fo:block></fo:static-content></fo:static-content>

• Finally, specify the content of page body:Finally, specify the content of page body:

Page 37: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3737

Example: Content Pages Example: Content Pages ContinueContinue• Assign a flow of blocks to region-body:Assign a flow of blocks to region-body:

<fo:flow flow-name="xsl-region-body"><fo:flow flow-name="xsl-region-body"> <fo:block font-size="14pt"> <fo:block font-size="14pt"> Watch this space! Watch this space! </fo:block> </fo:block>

<!-- normally all content of, say, a chapter<!-- normally all content of, say, a chapterwould come here -->would come here -->

</fo:flow> </fo:flow></fo:page-sequence> </fo:page-sequence>

• Formatting and rendering this gives … Formatting and rendering this gives …

Page 38: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3838

Example: Content Pages Example: Content Pages FormattedFormatted

Page 39: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

3939

Using FOs in PractiseUsing FOs in Practise• No one should write XSL FO document instances by handNo one should write XSL FO document instances by hand

• Instead, use Instead, use XSLTXSLT style rules to create formatting objects style rules to create formatting objects– root with layout masters for root with layout masters for match="/"match="/"– page-sequences with flows for major parts (like page-sequences with flows for major parts (like

chapters, or the entire document):chapters, or the entire document):

<xsl:template match="chapter"><xsl:template match="chapter"><fo:page-sequence master-reference= … > …<fo:page-sequence master-reference= … > …

<fo:flow flow-name="xsl-region-body" … > <fo:flow flow-name="xsl-region-body" … > <xsl:apply-templates/><xsl:apply-templates/> </fo:flow> </fo:flow>

</fo:page-sequence> </fo:page-sequence> </xsl:template></xsl:template>

Page 40: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

4040

Mapping content elementsMapping content elements

– content elements would be mapped to blocks, content elements would be mapped to blocks, inlines, list-blocks, tables, … as appropriateinlines, list-blocks, tables, … as appropriate

• For example, headers:For example, headers:

<xsl:template match="header"><xsl:template match="header"> < <fo:blockfo:block font-size="14pt" font-size="14pt"

font-family="sans-serif" font-weight="bold" font-family="sans-serif" font-weight="bold" color="green" space-before="6pt" color="green" space-before="6pt" space-after="6pt"> space-after="6pt">

<xsl:apply-templates/><xsl:apply-templates/> </ </fo:blockfo:block> >

</xsl:template></xsl:template>

Page 41: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

4141

Examples of mapping content Examples of mapping content elementselements

• Formatting in-line emphasis:Formatting in-line emphasis:<xsl:template match="strong"><xsl:template match="strong">

<<fo:inlinefo:inline font-weight="bold"> font-weight="bold"><xsl:apply-templates/><xsl:apply-templates/>

</ </fo:inlinefo:inline>> </xsl:template></xsl:template>

<xsl:template match="emph"><xsl:template match="emph"> <<fo:inlinefo:inline font-style="italic"> font-style="italic">

<xsl:apply-templates/><xsl:apply-templates/> </ </fo:inlinefo:inline>>

</xsl:template></xsl:template>

Page 42: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

4242

SummarySummary

• It is a standard!It is a standard!– well, almost: a W3C Recommendationwell, almost: a W3C Recommendation– emerging implementations seem promisingemerging implementations seem promising

• XSL is a powerful (and complex) style XSL is a powerful (and complex) style language for XML documentslanguage for XML documents– allows arbitrary transformations of input allows arbitrary transformations of input

documentsdocuments– allows fine-tuned specification of formatted allows fine-tuned specification of formatted

representationrepresentation

Page 43: 1 XSL FO Extensible Stylesheet Language Formatting Objects An advanced style language for XML documents: An advanced style language for XML documents:

4343

Java applications for XSL Java applications for XSL formatting objectsformatting objects

– Java 2 Standard Edition requiredJava 2 Standard Edition required•Download at Download at www.java.sun.com/j2sewww.java.sun.com/j2se

– Xerces parser requiredXerces parser required•Download at Download at xml.apache.org/xerces-jxml.apache.org/xerces-j

– Xalan XSLT processor requiredXalan XSLT processor required•Download at Download at xml.apache.org/xalanxml.apache.org/xalan

– FOP requiredFOP required•Download at Download at xml.apache.org/fopxml.apache.org/fop


Recommended