sdpl 2002notes 6: xsl1 6 xsl: extensible stylesheet language n an advanced style language for xml...

42
SDPL 2002 Notes 6: XSL 1 6 6 XSL: Extensible Stylesheet XSL: Extensible Stylesheet Language Language An advanced style language for XML An advanced style language for XML documents: documents: 1. 1. Language for transforming XML documents: Language for transforming XML documents: XSLT 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) 6.1 Introduction and Overview 6.1 Introduction and Overview 6.2 Using XSL Formatting Objects 6.2 Using XSL Formatting Objects

Upload: dorthy-smith

Post on 16-Dec-2015

230 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 1

66 XSL: Extensible Stylesheet Language XSL: Extensible Stylesheet Language

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 specifying XML vocabulary (of formatting objects) for specifying formatting semantics: formatting semantics: XSL version 1.0, W3C Rec. (15 October, 2001)XSL version 1.0, W3C Rec. (15 October, 2001)

6.1 Introduction and Overview6.1 Introduction and Overview 6.2 Using XSL Formatting Objects6.2 Using XSL Formatting Objects

Page 2: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 2

What is it?What is it?

An XSL style sheet specifies the presentation of a An XSL style sheet specifies the presentation of a class of XML documentsclass 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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 3

Example of XSL syntaxExample of XSL syntax

Formatting paragraph elements (Formatting paragraph elements (pp):):– NB:NB: An incomplete style sheet! An incomplete style sheet!

<?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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 4

6.1 Overview of XSL Formatting6.1 Overview of XSL Formatting

A A style sheet processorstyle sheet processor accepts an XML accepts an XML document and an XSL style sheet, and produces document and an XSL style sheet, and produces a formatted presentationa 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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 5

Transformation & FormattingTransformation & Formatting

Page 6: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 6

Basis of formattingBasis of formatting

Tree transformation adds information needed to Tree transformation adds information needed to format the result treeformat 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 tree nodes of the result tree

» for typographic abstractions like page-sequence, block, for typographic abstractions like page-sequence, block, in-line text, page reference, …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 of control the presentation of

formatting objects (indents, spacing, fonts, …)formatting objects (indents, spacing, fonts, …)» XSL 1.0 defines 246 formatting properties; many XSL 1.0 defines 246 formatting properties; many

common with CSS2common with CSS2

Page 7: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 7

FormattingFormatting

Formatting-object tree interpreted to produce the Formatting-object tree interpreted to produce the representationrepresentation

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

Properties control the formatting of a FOProperties control the formatting of a FO– some directly, e.g.,some directly, e.g., colorcolor– some through constraints, e.g.,some through constraints, e.g., space-space-before.minimumbefore.minimum rendered form not uniquely defined by XSLrendered form not uniquely defined by XSL

Page 8: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 8

Areas and Area TreeAreas and Area Tree

Formatting generates an Formatting generates an area treearea tree consisting of consisting of nested rectangular areasnested 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 a causes the area tree to appear on a mediummedium– 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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 9

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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 10

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

Page 11: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 11

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"font-size="12pt", , start-indent="2em"start-indent="2em" become traits become traits font-size="12pt"font-size="12pt", , start-indent="24pt"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., page some traits only available as a result of formatting, e.g., page

numbers numbers

Page 12: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 12

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 “, relative to “writing-modewriting-mode”” powerful source selection and manipulation powerful source selection and manipulation

(with XPath/XSLT)(with XPath/XSLT)

Page 13: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 13

XSL Area ModelXSL Area Model

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

» page breakspage breaks additional block areas additional block areas

» line breaks line breaks additional line areas additional line areas

Each area tree node (except root) is associated to Each area tree node (except root) is associated to a rectangular portion of the output mediuma 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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 14

Content, Padding and BorderContent, Padding and Border

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

space-beforespace-before

space-afterspace-after

start-start-

indentindent

end-indentend-indent

Page 15: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 15

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:blockfo:block, which creates block areas, 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 (normally left-to-right)left-to-right)

– characters rendered using characters rendered using fo:characterfo:character, which , 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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 16

Formatting objects and propertiesFormatting objects and properties

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-list-block, list-item, list-item-label, list-item-body, external-graphic, basic-link, float, item-body, external-graphic, basic-link, float, footnote, ...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, font-size, space-before, end-indent, text-align, text-indent, text-indent, … …

– many common with CSS2many common with CSS2

Page 17: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 17

Some central formatting objects 1/3Some central formatting objects 1/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-bodyregion-body (for page content) (for page content)» region-before, region-after, region-region-before, region-after, region-startstart and and region-endregion-end (for header, footer, and left and right sidebar)(for header, footer, and left and right sidebar)

Page 18: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 18

Page regionsPage regions

A simple page can contain 1-5 regions, specified by child A simple page can contain 1-5 regions, specified by child elements of the elements of the simple-page-mastersimple-page-master

Page 19: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 19

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-sequencefo: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 pagescontents of pages

Page 20: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 20

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

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

sequence-master) for, say, each chaptersequence-master) for, say, each chapter fo:flowfo:flow

– child objects of child objects of page-sequencepage-sequencess– 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

NBNB: No ‘page’-formatting objects: No ‘page’-formatting objects– pages created by the formatterpages created by the formatter

Page 21: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 21

Content objects for pagesContent objects for pages

Slightly simplified:Slightly simplified:

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

Block-level object+Block-level object+

fo:page-sequencefo:page-sequence++

fo:flowfo:flow

Block-level object+Block-level object+

Page 22: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 22

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

fo:blockfo:block– commonly used for paragraphs, titles, …commonly used for paragraphs, titles, …– may contain text, other may contain text, other blockblocks, ors, or

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

fo:tablefo:table for formatting tabular materialfor formatting tabular material fo:list-blockfo:list-block to format lists of to format lists of

– fo:list-itemfo:list-items ofs of» fo:list-item-labelfo:list-item-label and and fo:list-item-bodyfo:list-item-body

Page 23: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 23

““Hello world” result tree as XSL documentHello world” result tree as XSL document

<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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 24

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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 25

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. aural)111 formatting properties (out of 246, or 228 w.o. aural)

Page 26: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 26

6.2 An XSL-FO Example6.2 An XSL-FO Example

From From J. David Eisenberg: Using XSL Formatting Objects. J. David Eisenberg: Using XSL Formatting Objects. XML.com, January 17, 2001, XML.com, January 17, 2001, (acknowledging the loan of (acknowledging the loan of some graphics)some graphics)

XSL FOs for a version of a handbook of SpanishXSL FOs for a version of a handbook of Spanish– Tedious to manually mark-up document instances with Tedious to manually mark-up document instances with

XSL formatting objects; Think of this as the result of an XSL formatting objects; Think of this as the result of an XSLT transformationXSLT transformation

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

Page 27: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 27

Example: Page dimensions and marginsExample: Page dimensions and margins

<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 similarplus similar simple-page-master simple-page-masterss with with

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

Page 28: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 28

Intended layout of pagesIntended layout of pages

Page 29: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 29

Page regionsPage regions

A simple page can contain 1-5 regions, specified by child A simple page can contain 1-5 regions, specified by child elements of the 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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 30

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 … --> NBNB:: body body uses all space inside page marginsuses all space inside page margins

margins of margins of region-body region-body have to accommodate other regions!have to accommodate other regions!

Page 31: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 31

Example: Page SequencesExample: Page Sequences

Next: masters for Next: masters for sequencessequences of content pages, using the of content pages, using the defined defined simple-page-mastersimple-page-masterss– 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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 32

Page SequencesPage Sequences

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

» oror "last" "last", or, or "rest" "rest" (neither first or last), or(neither first or last), or "any" "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 end for example, to generate a blank page to force chapters to end

at even-numbered pagesat even-numbered pages

Next: Specifying the sequences of content pagesNext: Specifying the sequences of content pages– by naming masters to be used, and attaching content by naming masters to be used, and attaching content flowflows to regionss to regions

Page 33: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 33

Example: Contents of the Cover PageExample: Contents of the Cover Page

<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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 34

Example: Cover Page FormattedExample: Cover Page Formatted

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

Page 35: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 35

Example: Content PagesExample: Content Pages

Finally, a Finally, a page-sequencepage-sequence for content pagesfor content pages– with with static-contentstatic-content for the header and footer, and for the header and footer, and

a a flow flow for page bodies: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> Spanish Review Handbook </fo:block> </fo:</fo:static-contentstatic-content>>

Page 36: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 36

Example: Content Pages ContinueExample: Content Pages Continue

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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 37

Example: Content Pages ContinueExample: Content Pages Continue

Assign a Assign a flow flow of of blocksblocks to to region-bodyregion-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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 38

Example: Content Pages FormattedExample: Content Pages Formatted

Page 39: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 39

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 root with layout masters for with layout masters for match="/"match="/"– page-sequencespage-sequences with with flowsflows for major parts (like 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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 40

Mapping content elementsMapping content elements

– content elements would be mapped to content elements would be mapped to blocksblocks, , inlinesinlines, , list-blockslist-blocks, , tablestables, … as appropriate, … 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: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 41

Examples of mapping content elementsExamples of mapping content elements

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>

More examples in the exercisesMore examples in the exercises

Page 42: SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:

SDPL 2002 Notes 6: XSL 42

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 documentsallows arbitrary transformations of input documents– allows fine-tuned specification of formatted allows fine-tuned specification of formatted

representationrepresentation