SDPL 2004Notes 6: XSL Formatting1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML.
6 XSL: Extensible Stylesheet LanguageAn advanced style language for XML documents:1. Language for transforming XML documents: XSLT2. XML vocabulary ( markup language) for specifying formatting: XSL version 1.0, W3C Rec. (15 October, 2001)written for implementers of XSL processors6.1 Introduction and Overview6.2 XSL Formatting by ExampleNotes 6: XSL FormattingWhat is it?An XSL style sheet specifies the presentation of a class of XML documentsby describing an XSLT transformation of the XML document into an XML document that uses the formatting vocabulary XSL FO: a markup language to describe formatting XSL builds on CSS2 and DSSSL DSSSL an ISO-standardised, but mainly unimplemented SGML style languageNotes 6: XSL FormattingExample of XSL syntaxFormatting paragraph elements (p):NB: An incomplete style sheet!Notes 6: XSL Formatting6.1 Overview of XSL FormattingA style sheet processor accepts an XML document and an XSL style sheet, and produces a formatted presentationTwo steps:1. (XSLT) transformation: XML source tree -> result tree2. (XSL FO) formattinginterpreting the result tree to produce formatted presentationNotes 6: XSL FormattingTransformation & FormattingXSLT scriptNotes 6: XSL FormattingBasis of formattingTree transformation adds information needed to format the result treeFormatting semantics expressed using a formatting vocabulary, offormatting objects (FOs), nodes of the result treefor typographic abstractions like page-sequence, block, in-line text, page reference, XSL 1.0 defines 56 formatting object classesformatting properties control the presentation of formatting objects (indents, spacing, fonts, )XSL 1.0 defines 248 formatting properties; many common with CSS2Notes 6: XSL FormattingFormattingFormatting-object tree interpreted to produce the representationEach FO specifies a part of pagination, layout and styling applied to its contentProperties control the formatting of a FOsome directly, e.g., colorsome through constraints, e.g., space-before.minimum -> the final rendering is not uniquely defined by XSLNotes 6: XSL FormattingAreas and Area TreeFormatting generates an area tree consisting of nested rectangular areasinline areas (e.g. glyph areas) within line areaslines within block areasblocks within regions of a pageRendering causes the area tree to appear on a mediumareas printed on a sequence of sheets (or displayed as a single scroll in a browser)Notes 6: XSL FormattingGenerating the Area Tree (1/3)Formatting a gradual and complex processConceptual process of XSL formatting:(XSL FO) Element and attribute treetarget of transformation, source of formattingconsists of element, attribute, and text nodestransformed into a Formatting object tree (XSL FO Elem&attr tree)consists of formatting objects with propertiesmore detailed: each character its own objectNotes 6: XSL FormattingGenerating the Area Tree (2/3)Notes 6: XSL FormattingGenerating the Area Tree (3/3)Properties of the formatting object tree refined into traits (muotoilupiirre, piirre)e.g., by propagating inherited properties, and computing absolute values for relative propertiese.g., properties font-size="12pt", start-indent="2em" become traits font-size="12pt", start-indent="24pt"traits control generation of areas out of formatting objectssome traits only available as a result of formatting, e.g., page numbers Notes 6: XSL FormattingBenefits of XSLRich model and vocabulary for XML stylesheetsPowerful selection and manipulation ( XSLT)Pagination and layout extend existing ones area model a superset of the CSS2 box modele.g., different writing directions; footnotes, page number refs.Support of non-western writing directions> distances expressed in terms of before/after (for block-progression-direction), and start/end (for inline-progression-direction)Notes 6: XSL FormattingXSL Area ModelFormatting objects generate areaseach 0 or morepage breaks -> additional block areasline breaks -> additional line areasEach area tree node (except root) associated to a rectangular portion of the output mediumAn area has a content-rectangleportion for child areasoptionally surrounded by a border and paddingNotes 6: XSL FormattingContent, Padding and BorderFor compatibility also CSS-like margins margin-top, -right, -bottom and -left space-beforespace-afterstart- indentend-indentspace-startspace-endNotes 6: XSL FormattingTwo area typesblock-areasgenerated in block-progression-direction (normally top-to-bottom)paragraphs and titles normally rendered using fo:block, which creates block areasline-area a special case: no borders or paddinginline-areasgenerated in inline-progression-direction (normally left-to-right)characters rendered using fo:character, which generates glyph-area inline-areasno child areas, a single glyph image as contentNotes 6: XSL FormattingFormatting objects and propertiesXSL 1.0 defines 56 formatting objects page-sequence, simple-page-master, block, inline, list-block, list-item, list-item-label, list-item-body, external-graphic, basic-link, float, footnote, table, table-row, table-column, ... and 248 properties master-reference, background-color, font-family, font-size, space-before, start-indent, end-indent, text-align, text-indent, many common with CSS2Notes 6: XSL FormattingSome central formatting objects 1/3fo:roottop node of the formatting object treea wrapper for all the rest fo:simple-page-mastermodel of the geometry of pagesregion-body (for page content)region-before (for header), region-after (for footer), region-start and region-end (for left and right sidebar)Notes 6: XSL FormattingPage regionsA simple page can contain 1-5 regions, specified by child elements of the simple-page-masterNotes 6: XSL FormattingTop-level formatting objectsSlightly simplified:fo:rootfo:layout-master-set(fo:simple-page-master | fo:page-sequence-master)+fo:page-sequence+fo:region- bodyfo:region- before?fo:region-end?fo:region-start?fo:region- after?fo:flowNotes 6: XSL FormattingSome central formatting objects 2/3fo:page-sequencespecifies the creation of page sequencespossibly different page-sequence (and page-sequence-master) for, say, each chapterfo:flowchild of a page-sequenceAttribute flow-name connects to a region with a matching region-name > the contents is distributed to that region of pagesNB: There are no page-formatting objectspages created by the formatterNotes 6: XSL FormattingContent objects for pagesSlightly simplified:fo:static-content*Block-level object+fo:page-sequence+fo:flowBlock-level object+(repeated on every page)(distributed to pages)Notes 6: XSL FormattingSome block-level objectsfo:blockcommonly used for paragraphs, titles, may contain text, other blocks, orfo:inline (to change properties, e.g., font-style of inline text)fo:table for formatting tabular materialfo:list-block to format lists of fo:list-items of fo:list-item-label and fo:list-item-bodyNotes 6: XSL FormattingHello world result tree as an XSL document Hello World Notes 6: XSL FormattingImplementations?W3C XSL Rec rather recent (10/2001)What is the state of implementations?Some promising/interesting ones (2004):XEP by RenderX (XSL-FO to PS/PDF formatter), XSL Formatter by Antenna House$0 $5000 (evaluation server versions; April 2004)Adobe Document ServerPassive TeXset of TeX macros to process XSL-FO by Sebastian RahtzApache FOPNotes 6: XSL FormattingApache FOPFOP (Formatting Objects Processor) by J. Tauberfop: a man who pays too much attention to his appearancedonated to XML Apache project (http://xml.apache.org/fop/)open-source freewareJava-based XML/XSL-FO to PDF (or MIF/PCL/TXT/...) processorNot complete, but implements a useful subset of XSL 1.0 Notes 6: XSL FormattingFOP 0.20.5 XSL-FO-Compliancehttp://xml.apache.org/fop/compliance.htmlNotes 6: XSL Formatting6.2 XSL-FO by ExampleFrom J. David Eisenberg: Using XSL Formatting Objects. XML.com, January 17, 2001, (acknowledging the loan of some graphics)XSL FO instance for a handbook of SpanishNB: XSL FO is not designed to be hand-authoredConsider this as a machine-generated result (of an XSLT transformation)Overall structure of fo:root: specification ofpage masters, followed bythe content of the pagesNotes 6: XSL FormattingExample: Page dimensions and marginsplus similar simple-page-masters with master-name="rightPage" (identical)master-name="leftPage" (left and right margins switched)Notes 6: XSL FormattingIntended layout of pagesNotes 6: XSL FormattingPage regionsA simple page can contain 1-5 regions, specified by child elements of the simple-page-masterLets refine the page masters with regionsNotes 6: XSL FormattingExample: Region dimensions NB: body uses all space inside page margins -> margins of region-body have to accommodate other regions! Notes 6: XSL FormattingLayout of Page RegionsNotes 6: XSL FormattingExample: Page SequencesNext: masters for sequences of content pages, using the defined simple-page-mastersrepeatedly alternate masters for left and right pages: Notes 6: XSL FormattingPage SequencesOther attributes of conditional-page-master-reference to select the page master to be used:page-position="first" or "last", or "rest" (neither first or last), or "any"blank-or-not-blank="blank"/"not-blank"Next: Specifying the sequences of content pagesby naming masters to be used, and connecting content flows to regionsNotes 6: XSL FormattingExample: Contents of the Cover Page Spanish Review Handbook Copyright 2001 J. David Eisenberg A Catcode Production Notes 6: XSL FormattingExample: Cover Page FormattedFormatting the first page-sequence gives ... Notes 6: XSL FormattingExample: Content PagesFinally, a page-sequence for content pageswith static-content for the header and footer, and a flow for contents of pages: Spanish Review Handbook Notes 6: XSL FormattingExample: Content Pages ContinueContent for page footers: Pgina Finally, specify the content of the page body:Notes 6: XSL FormattingExample: Content Pages ContinueAssign a flow of blocks to region-body: Watch this space! Formatting and rendering this gives Notes 6: XSL FormattingExample: Content Pages FormattedNotes 6: XSL FormattingUsing FOs in PractiseXSL FO instances should not be created manuallyInstead, use XSLT style rules to create formatting objectsfo:root with layout masters for match="/"page-sequences with a flow for major parts (like chapters, or the entire document): Notes 6: XSL FormattingMapping content elementscontent elements would be mapped to blocks, inlines, list-blocks, tables, as appropriateFor example, headers: Notes 6: XSL FormattingExamples of mapping content elementsFormatting in-line emphasis: More examples in the exercisesNotes 6: XSL FormattingSummaryIt is a standard!well, almost: a W3C Recommendationemerging implementations seem promisingcurrently used mainly for producing PDF browser support being expected XSL is a powerful (and complex) style language for XML documentsallows arbitrary transformations of input documentsallows fine-tuned specification of formatted representationNotes 6: XSL FormattingExpert Views on XSLWhat is XSL-FO and When Should I Use It in Seybold Report, 2(17) (Dec. 02) by S. Deach, an XSL 1.0 co-author and computer scientist at Adobe:XSL-FO is now in the early-adopter phaseIt is expected that a wide variety of authoring tools become available  I expect a significant adoption  over a three-to-five year time frameXSL-FO is best [.. in] generating content-driven documents in response to individual customer requestsToday, XSL is most useful if you need to produce customer-tailored, paginated documents on a server.Notes 6: XSL Formatting