1fb56eb5d6f14247f55715e7d90a0b7f.ppt
- Количество слайдов: 45
6 XSL: Extensible Stylesheet Language n An advanced style language for XML documents: 1. Language for transforming XML documents: XSLT 2. XML vocabulary (≈ markup language) for specifying formatting: XSL version 1. 0, W 3 C Rec. (15 October, 2001) » written for implementers of XSL processors n n 6. 1 Introduction and Overview 6. 2 XSL Formatting by Example SDPL 2004 Notes 6: XSL Formatting 1
What is it? n An XSL style sheet specifies the presentation of a class of XML documents – by 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 n XSL builds on CSS 2 and DSSSL – DSSSL an ISO-standardised, but mainly unimplemented SGML style language SDPL 2004 Notes 6: XSL Formatting 2
Example of XSL syntax n Formatting paragraph elements (p): – NB: An incomplete style sheet! <xsl: stylesheet version='1. 0' xmlns: xsl="http: //www. w 3. org/1999/XSL/Transform" xmlns: fo="http: //www. w 3. org/1999/XSL/Format" > <xsl: template match="p"> <fo: block> <!-- settings for the first line: --> <fo: initial-property-set font-variant="small-caps"/> <xsl: apply-templates/> </fo: block> </xsl: template> </xsl: stylesheet> SDPL 2004 Notes 6: XSL Formatting 3
6. 1 Overview of XSL Formatting n n A style sheet processor accepts an XML document and an XSL style sheet, and produces a formatted presentation Two steps: 1. (XSLT) transformation: XML source tree -> result tree 2. (XSL FO) formatting » interpreting the result tree to produce formatted presentation SDPL 2004 Notes 6: XSL Formatting 4
Transformation & Formatting XSLT script SDPL 2004 Notes 6: XSL Formatting 5
Basis of formatting n n Tree transformation adds information needed to format the result tree Formatting semantics expressed using a formatting vocabulary, of – formatting objects (FOs), nodes of the result tree » for typographic abstractions like page-sequence, block, in -line text, page reference, … » XSL 1. 0 defines 56 formatting object classes – formatting properties control the presentation of formatting objects (indents, spacing, fonts, …) » XSL 1. 0 defines 248 formatting properties; many common with CSS 2 SDPL 2004 Notes 6: XSL Formatting 6
Formatting n n n Formatting-object tree interpreted to produce the representation Each FO specifies a part of pagination, layout and styling applied to its content Properties control the formatting of a FO – some directly, e. g. , color – some through constraints, e. g. , spacebefore. minimum -> the final rendering is not uniquely defined by XSL SDPL 2004 Notes 6: XSL Formatting 7
Areas and Area Tree n Formatting generates an area tree consisting of nested rectangular areas – – – n inline areas (e. g. glyph areas) within line areas lines within block areas blocks within regions of a page Rendering causes the area tree to appear on a medium – areas printed on a sequence of sheets (or displayed as a single scroll in a browser) SDPL 2004 Notes 6: XSL Formatting 8
Generating the Area Tree (1/3) n n n Formatting a gradual and complex process Conceptual process of XSL formatting: (XSL FO) Element and attribute tree – – – n target of transformation, source of formatting consists of element, attribute, and text nodes transformed into a … Formatting object tree ( XSL FO Elem&attr tree) – consists of formatting objects with properties – more detailed: each character its own object SDPL 2004 Notes 6: XSL Formatting 9
Generating the Area Tree (2/3) SDPL 2004 Notes 6: XSL Formatting 10
Generating the Area Tree (3/3) n Properties of the formatting object tree refined into traits (muotoilupiirre, piirre) – e. g. , by propagating inherited properties, and computing absolute values for relative properties » e. g. , properties font-size="12 pt", start-indent="2 em" become traits font-size="12 pt", start-indent="24 pt" – traits control generation of areas out of formatting objects – some traits only available as a result of formatting, e. g. , page numbers SDPL 2004 Notes 6: XSL Formatting 11
Benefits of XSL n n n Rich model and vocabulary for XML stylesheets Powerful selection and manipulation (← XSLT) Pagination and layout extend existing ones – area model a superset of the CSS 2 box model » e. g. , different writing directions; footnotes, page number refs. n Support of non-western writing directions – > distances expressed in terms of before/after (for block-progression-direction), and start/end (for inline-progression-direction) SDPL 2004 Notes 6: XSL Formatting 12
XSL Area Model n Formatting objects generate areas – each 0 or more » page breaks -> additional block areas » line breaks -> additional line areas n n Each area tree node (except root) associated to a rectangular portion of the output medium An area has a content-rectangle – portion for child areas – optionally surrounded by a border and padding SDPL 2004 Notes 6: XSL Formatting 13
Content, Padding and Border space-before startindent end-indent For compatibility also CSS-like margins margin-top, -right, -bottom and -left space-after space-start SDPL 2004 space-end Notes 6: XSL Formatting 14
Two area types n block-areas – generated in block-progression-direction (normally top-to-bottom) – paragraphs and titles normally rendered using fo: block, which creates block areas – line-area a special case: no borders or padding n inline-areas – generated in inline-progression-direction (normally left-to-right) – characters rendered using fo: character, which generates glyph-area inline-areas » no child areas, a single glyph image as content SDPL 2004 Notes 6: XSL Formatting 15
Formatting objects and properties n XSL 1. 0 defines 56 formatting objects … page-sequence, simple-page-master, block, inline, list-block, list-item-label, list-item -body, external-graphic, basic-link, float, footnote, table-row, table-column, . . . n and 248 properties master-reference, background-color, font-family, font-size, space-before, start-indent, endindent, text-align, text-indent, … – many common with CSS 2 SDPL 2004 Notes 6: XSL Formatting 16
Some central formatting objects 1/3 n fo: root – top node of the formatting object tree – a wrapper for all the rest n fo: simple-page-master – model of the geometry of pages » region-body (for page content) » region-before (for header), region-after (for footer), region-start and region-end (for left and right sidebar) SDPL 2004 Notes 6: XSL Formatting 17
Page regions n A simple page can contain 1 -5 regions, specified by child elements of the simple-page-master SDPL 2004 Notes 6: XSL Formatting 18
Top-level formatting objects n Slightly simplified: fo: root fo: layout-master-set contents of pages fo: page-sequence+ (fo: simple-page-master | fo: page-sequence-master)+ fo: regionbody fo: regionafter? fo: regionstart? before? fo: regionend? SDPL 2004 Notes 6: XSL Formatting fo: flow specify masters for page sequences by referring to simple-page-masters 19
Some central formatting objects 2/3 n fo: page-sequence – specifies the creation of page sequences – possibly different page-sequence (and pagesequence-master) for, say, each chapter n n fo: flow – child of a page-sequence – Attribute flow-name connects to a region with a matching region-name – > the contents is distributed to that region of pages NB: There are no ‘page’-formatting objects – pages created by the formatter SDPL 2004 Notes 6: XSL Formatting 20
Content objects for pages n Slightly simplified: fo: page-sequence+ fo: flow fo: static-content* (repeated on every page) Block-level object+ SDPL 2004 (distributed to pages) Block-level object+ Notes 6: XSL Formatting 21
Some block-level objects n fo: block – commonly used for paragraphs, titles, … – may contain text, other blocks, or » fo: inline (to change properties, e. g. , font-style of inline text) n n fo: table formatting tabular material fo: list-block to format lists of – fo: list-items of » fo: list-item-label and » fo: list-item-body SDPL 2004 Notes 6: XSL Formatting 22
“Hello world” result tree as an XSL document <fo: root xmlns: fo="http: //www. w 3. org/1999/XSL/Format"> <fo: layout-master-set> <fo: simple-page-master-name="page"> <fo: region-body/> </fo: simple-page-master> </fo: layout-master-set> <fo: page-sequence master-reference="page"> <!--use 'page' master--> <fo: flow-name="xsl-region-body"> <fo: block>Hello World</fo: block> </fo: flow> </fo: page-sequence> </fo: root> SDPL 2004 Notes 6: XSL Formatting 23
Implementations? n n n W 3 C XSL Rec rather recent (10/2001) What is the state of implementations? Some promising/interesting ones (2004): – XEP by Render. X (XSL-FO to PS/PDF formatter), XSL Formatter by Antenna House » $0 … $5000 (evaluation … server versions; April 2004) – Adobe Document Server – Passive Te. X » set of Te. X macros to process XSL-FO by Sebastian Rahtz – Apache FOP SDPL 2004 Notes 6: XSL Formatting 24
Apache FOP n FOP (Formatting Objects Processor) by J. Tauber » “fop: a man who pays too much attention to his appearance” – donated to XML Apache project (http: //xml. apache. org/fop/) – open-source freeware – Java-based XML/XSL-FO to PDF (or MIF/PCL/TXT/. . . ) processor – Not complete, but implements a useful subset of XSL 1. 0 SDPL 2004 Notes 6: XSL Formatting 25
FOP 0. 20. 5 XSL-FO-Compliance n http: //xml. apache. org/fop/compliance. html Implemented formatting objects formatting properties non-aural properties SDPL 2004 fully 36 (64%) 95 (38%) 95 (41%) partially 17 no 3 (30%) (5%) 110 43 total 56 (44%) 110 (48%) Notes 6: XSL Formatting 248 (17%) 25 230 (11%) 26
6. 2 XSL-FO by Example n From J. David Eisenberg: Using XSL Formatting Objects. XML. com, January 17, 2001, (acknowledging the loan of some graphics) n XSL FO instance for a handbook of Spanish – NB: XSL FO is not designed to be hand-authored – Consider this as a machine-generated result (of an XSLT transformation) n Overall structure of fo: root: specification of – – page masters, followed by the content of the pages SDPL 2004 Notes 6: XSL Formatting 27
Example: Page dimensions and margins <fo: layout-master-set> <fo: simple-page-master-name="cover" page-height="12 cm" page-width="12 cm" margin-top="0. 5 cm" margin-bottom="0. 5 cm" margin-left="1 cm" margin-right="0. 5 cm" > </fo: simple-page-master> … </fo: layout-master-set> n plus similar simple-page-masters with – master-name="right. Page" (identical) – master-name="left. Page" (left and right margins switched) SDPL 2004 Notes 6: XSL Formatting 28
Intended layout of pages SDPL 2004 Notes 6: XSL Formatting 29
Page regions n A simple page can contain 1 -5 regions, specified by child elements of the simple-page-master n Let´s refine the page masters with regions SDPL 2004 Notes 6: XSL Formatting 30
Example: Region dimensions <fo: simple-page-master-name="cover" … dimensions and margins as above … > <fo: region-body margin-top="3 cm" /> </fo: simple-page-master> <fo: simple-page-master-name="left. Page" … > <fo: region-before extent="1 cm"/> <fo: region-after extent="1 cm"/> <fo: region-body margin-top="1. 1 cm" margin-bottom="1. 1 cm" /> </fo: simple-page-master> <!-- and "right. Page" similarly … --> n NB: body uses all space inside page margins -> margins of region-body have to accommodate other regions! SDPL 2004 Notes 6: XSL Formatting 31
Layout of Page Regions SDPL 2004 Notes 6: XSL Formatting 32
Example: Page Sequences n Next: masters for sequences of content pages, using the defined simple-page-masters – repeatedly alternate masters for left and right pages: <fo: page-sequence-master-name="contents"> <fo: repeatable-page-master-alternatives> <fo: conditional-page-master-reference="left. Page" odd-or-even="even"/> <fo: conditional-page-master-reference ="right. Page" odd-or-even="odd"/> </fo: repeatable-page-master-alternatives> </fo: page-sequence-master> SDPL 2004 Notes 6: XSL Formatting 33
Page Sequences n Other attributes of conditional-page-masterreference 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" n Next: Specifying the sequences of content pages – by naming masters to be used, and connecting content flows to regions SDPL 2004 Notes 6: XSL Formatting 34
Example: Contents of the Cover Page <fo: page-sequence master-reference="cover"> <fo: flow-name="xsl-region-body"> <fo: block font-family="Helvetica" font-size="18 pt" text-align="end"> Spanish Review Handbook </fo: block> <fo: block font-family="Helvetica" font-size="12 pt" text-align="end" space-after="36 pt">Copyright © 2001 J. David Eisenberg</fo: block> <fo: block text-align="end"> A Catcode Production </fo: block> </fo: flow> </fo: page-sequence> SDPL 2004 Notes 6: XSL Formatting 35
Example: Cover Page Formatted n Formatting the first page-sequence gives. . . SDPL 2004 Notes 6: XSL Formatting 36
Example: Content Pages n Finally, a page-sequence for content pages – with static-content for the header and footer, and a flow for contents of pages: <fo: page-sequence master-reference="contents" initial-page-number="2"> <!-- Content of page headers: --> <fo: static-content flow-name="xsl-region-before"> <fo: block font-family="Helvetica" font-size="10 pt" text-align="center"> Spanish Review Handbook </fo: block> </fo: static-content> SDPL 2004 Notes 6: XSL Formatting 37
Example: Content Pages Continue n Content for page footers: <!-- static-content is repeated on every page --> <fo: static-content flow-name="xsl-region-after"> <fo: block font-family="Helvetica" font-size="10 pt" text-align="center"> Pá gina <fo: page-number /> </fo: block> </fo: static-content> n Finally, specify the content of the page body: SDPL 2004 Notes 6: XSL Formatting 38
Example: Content Pages Continue n Assign a flow of blocks to region-body: <fo: flow-name="xsl-region-body"> <fo: block font-size="14 pt"> Watch this space! </fo: block> <!-- normally all content of, say, a chapter would come here --> </fo: flow> </fo: page-sequence> n Formatting and rendering this gives … SDPL 2004 Notes 6: XSL Formatting 39
Example: Content Pages Formatted SDPL 2004 Notes 6: XSL Formatting 40
Using FOs in Practise n n XSL FO instances should not be created manually Instead, use XSLT style rules to create formatting objects – fo: root with layout masters for match="/" – page-sequences with a flow for major parts (like chapters, or the entire document): <xsl: template match="chapter"> <fo: page-sequence master-reference= … > … <fo: flow-name="xsl-region-body" … > <xsl: apply-templates/> </fo: flow> </fo: page-sequence> </xsl: template> SDPL 2004 Notes 6: XSL Formatting 41
Mapping content elements – content elements would be mapped to blocks, inlines, list-blocks, tables, … as appropriate n For example, headers: <xsl: template match="header"> <fo: block font-size="14 pt" font-family="sans-serif" font-weight="bold" color="green" space-before="6 pt" space-after="6 pt"> <xsl: apply-templates/> </fo: block> </xsl: template> SDPL 2004 Notes 6: XSL Formatting 42
Examples of mapping content elements n Formatting in-line emphasis: <xsl: template match="strong"> <fo: inline font-weight="bold"> <xsl: apply-templates/> </fo: inline> </xsl: template> <xsl: template match="emph"> <fo: inline font-style="italic"> <xsl: apply-templates/> </fo: inline> </xsl: template> n More examples in the exercises SDPL 2004 Notes 6: XSL Formatting 43
Summary n XSL is a powerful (and complex) style language for XML documents – – n allows arbitrary transformations of input documents allows fine-tuned specification of formatted representation It is a standard! – – – well, almost: a W 3 C Recommendation emerging implementations seem promising currently used mainly for producing PDF » browser support being expected … SDPL 2004 Notes 6: XSL Formatting 44
Expert Views on XSL n ”What 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’ phase” – ”It is expected that a wide variety of authoring tools become available […] I expect a significant adoption […] over a three-to-five year time frame” – ”XSL-FO is best [. . in] generating content-driven documents in response to individual customer requests” – ”Today, XSL is most useful if you need to produce customertailored, paginated documents on a server. ” SDPL 2004 Notes 6: XSL Formatting 45
1fb56eb5d6f14247f55715e7d90a0b7f.ppt