SDPL 2004Notes 6: XSL Formatting1 6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML

  • View
    216

  • Download
    0

Embed Size (px)

Transcript

  • 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 Example

    Notes 6: XSL Formatting

  • What 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 language

    Notes 6: XSL Formatting

  • Example of XSL syntaxFormatting paragraph elements (p):NB: An incomplete style sheet!

    Notes 6: XSL Formatting

  • 6.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 presentation

    Notes 6: XSL Formatting

  • Transformation & FormattingXSLT script

    Notes 6: XSL Formatting

  • Basis 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 CSS2

    Notes 6: XSL Formatting

  • FormattingFormatting-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 XSL

    Notes 6: XSL Formatting

  • Areas 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 Formatting

  • Generating 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 object

    Notes 6: XSL Formatting

  • Generating the Area Tree (2/3)

    Notes 6: XSL Formatting

  • Generating 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 Formatting

  • Benefits 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 Formatting

  • XSL 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 padding

    Notes 6: XSL Formatting

  • Content, Padding and BorderFor compatibility also CSS-like margins margin-top, -right, -bottom and -left space-beforespace-afterstart- indentend-indentspace-startspace-end

    Notes 6: XSL Formatting

  • Two 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 content

    Notes 6: XSL Formatting

  • Formatting 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 CSS2

    Notes 6: XSL Formatting

  • Some 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 Formatting

  • Page regionsA simple page can contain 1-5 regions, specified by child elements of the simple-page-master

    Notes 6: XSL Formatting

  • Top-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:flow

    Notes 6: XSL Formatting

  • Some 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 formatter

    Notes 6: XSL Formatting

  • Content 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 Formatting

  • Some 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-body

    Notes 6: XSL Formatting

  • Hello world result tree as an XSL document

    Hello World

    Notes 6: XSL Formatting

  • Implementations?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 FOP

    Notes 6: XSL Formatting

  • Apache 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 Formatting

  • FOP 0.20.5 XSL-FO-Compliancehttp://xml.apache.org/fop/compliance.html

    Notes 6: XSL Formatting

  • 6.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 pages

    Notes 6: XSL Formatting

  • Example: Page dimensions and margins

    plus similar simple-page-masters with master-name="rightPage" (identical)master-name="leftPage" (left and right margins switched)

    Notes 6: XSL Formatting

  • Intended layout of pages

    Notes 6: XSL Formatting

  • Page regionsA simple page can contain 1-5 regions, specified by child elements of the simple-page-masterLets refine the page masters with regions

    Notes 6: XSL Formatting

  • Example: Region dimensions NB: body uses all space inside page margins -> margins of region-body have to accommodate other regions!

    Notes 6: XSL Formatting

  • Layout of Page Regions

    Notes 6: XSL Formatting

  • Example: Page SequencesNext: masters for sequences of content pages, using the defined simple-page-mastersrepeatedly alternate masters for left and right pages:

    Notes 6: XSL Formatting

  • Page SequencesOther attributes of conditional-page-master-reference to select the page master to be used:page-positi