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
42
Embed
SDPL 2002Notes 6: XSL1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents:
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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
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
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!
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
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-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
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)
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
SDPL 2002 Notes 6: XSL 10
Generating the Area Tree (2/3)Generating the Area Tree (2/3)
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
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)
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
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
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
SDPL 2002 Notes 6: XSL 16
Formatting objects and propertiesFormatting objects and properties
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)
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
for page sequences for page sequences by referring to by referring to simple-page-masterssimple-page-masters
contents of pagescontents of pages
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
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+
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
SDPL 2002 Notes 6: XSL 23
““Hello world” result tree as XSL documentHello world” result tree as XSL document
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
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)
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
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)
SDPL 2002 Notes 6: XSL 28
Intended layout of pagesIntended layout of pages
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
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 … > >
<!-- 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!
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:
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
SDPL 2002 Notes 6: XSL 33
Example: Contents of the Cover PageExample: Contents of the Cover Page
Formatting the first Formatting the first page-sequencepage-sequence gives ... gives ...
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">
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):
– content elements would be mapped to content elements would be mapped to blocksblocks, , inlinesinlines, , list-blockslist-blocks, , tablestables, … as appropriate, … as appropriate
More examples in the exercisesMore examples in the exercises
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