sdpl 20076: xsl formatting1 6 xsl: extensible stylesheet language n an advanced style language for...
TRANSCRIPT
SDPL 2007 6: XSL Formatting 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 for specifying formatting: XML vocabulary for specifying formatting: XSL 1.0, W3C Rec. 10/01; XSL 1.1 Rec. 12/06 XSL 1.0, W3C Rec. 10/01; XSL 1.1 Rec. 12/06
» written for written for implementersimplementers of XSL processors of XSL processors
6.1 Introduction and Overview6.1 Introduction and Overview 6.2 XSL Formatting by Example6.2 XSL Formatting by Example
SDPL 2007 6: XSL Formatting 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 an ISO-standardised, but mainly DSSSL an ISO-standardised, but mainly unimplemented SGML style languageunimplemented SGML style language
SDPL 2007 6: XSL Formatting 3
Example of XSL SyntaxExample of XSL Syntax
Formatting paragraphs (as part of a complete style sheet)Formatting paragraphs (as part of a complete style sheet)
<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="para[position() > 1]"><xsl:template match="para[position() > 1]"> <fo:block text-indent="1em" > <fo:block text-indent="1em" > <xsl:apply-templates/><xsl:apply-templates/> </fo:block></fo:block> </xsl:template></xsl:template>
</xsl:stylesheet></xsl:stylesheet>
SDPL 2007 6: XSL Formatting 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. 1. (XSLT) (XSLT) transformation: transformation:
XML XML source treesource tree result treeresult tree2. 2. (XSL FO)(XSL FO) formatting formatting
» interprets the result tree to produce formatted interprets the result tree to produce formatted presentationpresentation
SDPL 2007 6: XSL Formatting 5
Transformation & FormattingTransformation & Formatting
XSLT scriptXSLT script
SDPL 2007 6: XSL Formatting 6
Basis of formattingBasis of formatting
Transformation adds info to format the result treeTransformation adds info to format the result tree Formatting semantics expressed using a Formatting semantics expressed using a
formatting vocabularyformatting vocabulary, of, of– formatting objectsformatting 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 FO classes (XSL 1.1 adds 25) XSL 1.0 defines 56 FO classes (XSL 1.1 adds 25) – formatting propertiesformatting properties control the presentation of control the presentation of
formatting objects (indents, spacing, fonts, …)formatting objects (indents, spacing, fonts, …)» 248 formatting properties; 248 formatting properties;
many common with CSS2many common with CSS2
SDPL 2007 6: XSL Formatting 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 and and space-before.optimumspace-before.optimum final rendering is not uniquefinal rendering is not unique
SDPL 2007 6: XSL Formatting 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 as a single scroll in a browser)(or displayed as a single scroll in a browser)
SDPL 2007 6: XSL Formatting 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: (XSL FO)(XSL FO) Element and attribute tree Element 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 tree Formatting object tree ((XSL FO Elem&attr tree)XSL FO Elem&attr tree)– consists of formatting consists of formatting objectsobjects with with propertiesproperties– more detailed: each character its own objectmore detailed: each character its own object
SDPL 2007 6: XSL Formatting 10
Generating the Area Tree (2/3)Generating the Area Tree (2/3)
SDPL 2007 6: XSL Formatting 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 traits traits ((muotoilupiirre, piirremuotoilupiirre, piirre))– 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", , text-indent="2em"text-indent="2em" become traits become traits font-size="12pt"font-size="12pt", , text-indent="24pt"text-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
SDPL 2007 6: XSL Formatting 12
Benefits and Usage of XSLBenefits and Usage of XSL
Powerful selection and manipulation (Powerful selection and manipulation (← ← XSLT)XSLT) Extended pagination and layout capabilities Extended pagination and layout capabilities
– 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 writing directionsSupport of non-western writing directions– > distances in terms of > distances in terms of beforebefore//after after (for (for block-progression-block-progression-
directiondirection)), , and and startstart//end end (for (for inline-progression-directioninline-progression-direction))
"XSL most useful to produce tailored, paginated "XSL most useful to produce tailored, paginated documents on a server, in response to individual documents on a server, in response to individual customer requests” customer requests” (S. Deach, XSL 1.0 co-author, (S. Deach, XSL 1.0 co-author, Adobe)Adobe)
SDPL 2007 6: XSL Formatting 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) associated to a Each area tree node (except root) associated to a rectangular portion of the output mediumrectangular 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
SDPL 2007 6: XSL Formatting 14
Content, Padding and BorderContent, Padding and Border
For CSS-For CSS-compatibility also compatibility also
margin-topmargin-top, , -right-right, , -bottom-bottom andand -left-left
space-beforespace-before
space-afterspace-after
start-start-indentindent
end-indentend-indent
space-startspace-start space-endspace-end
space-start/end not space-start/end not supported by FOPsupported by FOP
SDPL 2007 6: XSL Formatting 15
Two area typesTwo area types
block-areasblock-areas– generated in generated in block-progression-directionblock-progression-direction
((beforebefore -> -> afterafter; 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 ((startstart -> -> endend; normally left-to-right); normally 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
SDPL 2007 6: XSL Formatting 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, table, table-row, table-column, footnote, table, table-row, table-column, ......
and 248 propertiesand 248 properties master-referencemaster-reference, , background-color, font-family, background-color, font-family, font-size, space-before, start-indent, end-font-size, space-before, start-indent, end-indent, text-align, text-indent,indent, text-align, text-indent, … …
– many common with CSS2many common with CSS2
SDPL 2007 6: XSL Formatting 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– model of the geometry of pagesmodel of the geometry of pages
» region-bodyregion-body (for page content) (for page content)» region-beforeregion-before (for header)(for header), , region-afterregion-after (for footer)(for footer), , region-startregion-start and and region-endregion-end (for left and right sidebar) (for left and right sidebar)
SDPL 2007 6: XSL Formatting 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
SDPL 2007 6: XSL Formatting 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
fo:flowfo:flow
SDPL 2007 6: XSL Formatting 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 of a child of a page-sequencepage-sequence– Attribute Attribute flow-nameflow-name connects to a region with a connects to a region with a
matching matching region-nameregion-name – > the contents is distributed to that region of pages> the contents is distributed to that region of pages
NBNB: There are no ‘page’-formatting objects: There are no ‘page’-formatting objects– pages created by the formatterpages created by the formatter
SDPL 2007 6: XSL Formatting 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+
(repeated on (repeated on every page)every page)
(distributed (distributed to pages)to pages)
SDPL 2007 6: XSL Formatting 22
Some block-level objectsSome block-level objects
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
SDPL 2007 6: XSL Formatting 23
““Hello world” result tree as an XSL documentHello world” result tree as an 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>
SDPL 2007 6: XSL Formatting 24
Implementations?Implementations?
W3C XSL Rec rather recent (10/01, 12/07)W3C XSL Rec rather recent (10/01, 12/07) What is the state of implementations?What is the state of implementations? Some promising/interesting ones (2004):Some promising/interesting ones (2004):
– XEP by RenderX (XSL-FO to PS/PDF XEP by RenderX (XSL-FO to PS/PDF formatter),formatter),XSL Formatter by Antenna HouseXSL Formatter by Antenna House
» $0 … $5,000 (evaluation … server versions; April 2004)$0 … $5,000 (evaluation … server versions; April 2004)
– Adobe Document ServerAdobe Document Server– 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
SDPL 2007 6: XSL Formatting 25
Apache FOPApache FOP
FOP (Formatting Objects Processor) by J. TauberFOP (Formatting Objects Processor) 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 PS/SVG/TXT/...) Java-based XML/XSL-FO to PDF (or PS/SVG/TXT/...)
processorprocessor– Not complete, but implements a useful subset of XSL 1.0Not complete, but implements a useful subset of XSL 1.0
SDPL 2007 6: XSL Formatting 26
FOP 0.93 XSL-FO ComplianceFOP 0.93 XSL-FO Compliance
http://xml.apache.org/fop/compliance.htmlhttp://xml.apache.org/fop/compliance.html
ImplementeImplementedd
fullyfully partiallpartiallyy
nono totaltotal
formatting formatting
objectsobjects 3939
(66%)(66%) 66
(10%)(10%) 1414
(24%)(24%) 5959(incl. 3 XSL (incl. 3 XSL 1.1 bookmark 1.1 bookmark FOs)FOs)
formattingformatting
propertiesproperties 144144
(64%)(64%) 1919
(8%)(8%) 6363
(28%)(28%) 226226(non-aural)(non-aural)
– 16 of 18 core functions implemented16 of 18 core functions implemented
SDPL 2007 6: XSL Formatting 27
6.2 XSL-FO by Example6.2 XSL-FO by 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 FO instance for a handbook of SpanishXSL FO instance for a handbook of Spanish– NBNB: XSL FO is not designed to be hand-authored: XSL FO is not designed to be hand-authored– Consider this as a machine-generated result Consider this as a machine-generated result
(of an XSLT transformation)(of an XSLT transformation) Overall structure ofOverall structure of fo:rootfo:root: specification of: specification of
– page masters, followed bypage masters, followed by– the content of the pagesthe content of the pages
SDPL 2007 6: XSL Formatting 28
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-mastersimple-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)
SDPL 2007 6: XSL Formatting 29
Intended layout of pagesIntended layout of pages
SDPL 2007 6: XSL Formatting 30
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´s refine the page masters with regionsLet´s refine the page masters with regions
SDPL 2007 6: XSL Formatting 31
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:<fo:region-bodyregion-body margin-top="3cm" /> 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:<fo:region-bodyregion-body margin-top="1.1cm" margin-bottom="1.1cm" /> margin-top="1.1cm" margin-bottom="1.1cm" /> <fo:<fo:region-beforeregion-before extent="1cm"/> extent="1cm"/> <fo:<fo:region-afterregion-after extent="1cm"/> extent="1cm"/> </fo:simple-page-master> </fo:simple-page-master>
<!-- and "rightPage"<!-- and "rightPage" similarly … -->similarly … --> NBNB:: bodybody uses all space inside page margins uses all space inside page margins
margins of margins of region-bodyregion-body have to accommodate other regions!have to accommodate other regions!
SDPL 2007 6: XSL Formatting 32
Layout of Page RegionsLayout of Page Regions
3 cm
SDPL 2007 6: XSL Formatting 33
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>>
SDPL 2007 6: XSL Formatting 34
Page SequencesPage Sequences
Other attributes of Other attributes of conditional-page-master-conditional-page-master-referencereference 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" Next: Specifying the sequences of content pagesNext: Specifying the sequences of content pages
– by naming masters to be used, by naming masters to be used, and connecting content and connecting content flowflows to regionss to regions
SDPL 2007 6: XSL Formatting 35
Example: Contents of the Cover PageExample: Contents of the Cover Page
<fo:<fo:page-sequencepage-sequence master-reference="cover"> master-reference="cover"> <fo: <fo:flowflow flow-name="xsl-region-body"> 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 © space-after="36pt">Copyright © 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: </fo:flowflow> > </fo:</fo:page-sequencepage-sequence>>
SDPL 2007 6: XSL Formatting 36
Example: Cover Page FormattedExample: Cover Page Formatted
Formatting the first Formatting the first page-sequencepage-sequence gives ... gives ...
SDPL 2007 6: XSL Formatting 37
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 flowflow for contents of pages: for contents of pages:<fo:<fo:page-sequencepage-sequence master-reference="contents" 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>>
SDPL 2007 6: XSL Formatting 38
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:<fo:static-contentstatic-content flow-name="xsl-region-after"> 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ágina Página <fo:page-number /><fo:page-number /> </fo:block> </fo:block></fo:</fo:static-contentstatic-content>>
Finally, specify the content of the page body:Finally, specify the content of the page body:
SDPL 2007 6: XSL Formatting 39
Example: Content Pages ContinueExample: Content Pages Continue
Assign a Assign a flowflow of of blockblocks to s to region-bodyregion-body::
<fo:<fo:flowflow flow-name=" flow-name="xsl-region-bodyxsl-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: </fo:flowflow>></fo:</fo:page-sequencepage-sequence>>
Formatting and rendering this gives … Formatting and rendering this gives …
SDPL 2007 6: XSL Formatting 40
Example: Content Pages FormattedExample: Content Pages Formatted
SDPL 2007 6: XSL Formatting 41
Using FOs in PractiseUsing FOs in Practise
XSL FO instances should not be created manuallyXSL FO instances should not be created manually Instead, use Instead, use XSLTXSLT rules to create formatting objects rules to create formatting objects
– fo:rootfo:root with layout masters for with layout masters for match="/"match="/"– page-sequencepage-sequences with a s with a flowflow 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>
SDPL 2007 6: XSL Formatting 42
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-weight="bold" font-size="14pt" font-weight="bold"
font-family="sans-serif" color="green" font-family="sans-serif" color="green" space-before="6pt" space-after="6pt"> space-before="6pt" space-after="6pt">
<xsl:apply-templates /> <xsl:apply-templates /> </ </fo:blockfo:block>>
</xsl:template></xsl:template>
SDPL 2007 6: XSL Formatting 43
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 in the exercisesMore in the exercises
SDPL 2007 6: XSL Formatting 44
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– currently used mainly for producing PDF currently used mainly for producing PDF
» browser support being expected … browser support being expected …
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