Presentation is loading. Please wait.

Presentation is loading. Please wait.

XSL Formatting Objects XSL-FO. Why XSL-FO? Some History The history of HTML shows that, in the early days, both its designers and its users were confused.

Similar presentations


Presentation on theme: "XSL Formatting Objects XSL-FO. Why XSL-FO? Some History The history of HTML shows that, in the early days, both its designers and its users were confused."— Presentation transcript:

1 XSL Formatting Objects XSL-FO

2 Why XSL-FO? Some History The history of HTML shows that, in the early days, both its designers and its users were confused about its purpose Initially, it was intended for specifying the structure of documents for the web –Its tags included (See hypertext/hypertext/WWW/MarkUp/Tags.html) These documents were then displayed using whatever rendering choices were made by the displaying program

3 Why XSL-FO? Some History (contd.) In the early days, there was some confusion People did not make the distinction between structure and style –Even Tim Berners-Lee made the mistake of writing “Most of the tags are just style tags: this goes for the headings H1 to H6, the lists UL and OL with list elements LI, the glossary DL with elements DT and DD. ” (See

4 Why XSL-FO? Some History (contd.) This confusion caused the mistaken introduction of rendering tags (and rendering attributes) into the language –For example: Elimination of this confusion led to the introduction of Cascading Style Sheets and the deprecation of rendering tags and attributes It is now recognized that there should be a sharp distinction between the specification of structure and of rendering This distinction was already recognized by the time that XML was developed

5 Why XSL-FO? Some History (contd.) The structure/rendering distinction is reflected in the separation between XML and XSL XML is used for specifying document structure XSL is used for specifying document rendering The W3 specification for XSL can be found here

6 Why XSL-FO? Some History (contd.) XSLT is able to do only part of the job of rendering XML documents XSLT is for specifying how to analyse the structure of an XML document in order to compute the appropriate rendering of the document But XSLT must be complemented by a second notation in which we can specify the desired rendering We have seen that HTML is sometimes used as the second notation However, XSL Formatting Objects (XSL-FO) is the more general notation for specifying the desired rendering

7 Why XSL-FO? Some History (contd.) It is common for XSLT to map XML documents into HTML documents This is because HTML has a rendering semantics However, HTML allows us to render XML documents only as web pages –using browsers as the rendering engines Frequently, we need to render XML as other kinds of documents, including –PDF files, –Image files We need another notation which can be used to specify the rendering of PDF files and images

8 Why XSL-FO? Some History (contd.) XSL has two parts –XSLT can be used to analyse the structure of an XML document, in order to generate a document in some other notation –XSL-FO is one such other notation XSL-FO is designed specifically for the purpose of describing the layout of documents –In this sense, its purpose is a little like that of CSS, –However, XSL-FO is quite different from CSS A layout description given in XSL-FO can be used to generate a growing variety of documents, including –PDF files, –Image files

9 XSL-FO is an XML application-specific language Every XSL-FO specification must be well-formed XML For technical reasons, it is not possible to have a comprehensive DTD for XSL-FO –However, an unofficial DTD is here Warning: this unofficial DTD was written by somebody from a company which produces a commercial FO processor program called XEP The unofficial DTD contains some commercial extensions which are associated with the namespace These extensions are identified in the DTD by use of the prefix rx:

10 XSL-FO is an XML application-specific language The namespace for XSL-FO is The prefix used is fo The root element in XSL-FO has the tag name root The declaration for this element in the unofficial DTD is Thus, the root element is of the form …

11 How do we use XSL-FO?

12 First, let's revisit how we used XSLT to view XML files in browsers

13 A reminder: viewing XML in a web browser The browser requests an XML document The XML document refers to an XSLT stylesheet –The browser then requests the stylesheet The browser's XSLT Engine generates HTML from XML+XSLT The browser's HTML engine renders the HTML in the browser window

14 Using a browser's XSLT engine to generate HTML from XML... Greetings Hello, !

15 ... Then rendering the HTML with the browser's HTML engine Greetings Hello, !

16 What happens if we try the same thing with XSL-FO as we just did with HTML?

17 Generating XSL-FO from XML Hello, !

18 How is the resultant XSL-FO rendered in the browser? Hello, Tom! Hello, Dick! Hello, Harry!

19 How is the resultant XSL-FO rendered in the browser? The browser cannot render XSL-FO Hello, Tom! Hello, Dick! Hello, Harry!

20 How is the resultant XSL-FO rendered in the browser? The browser cannot render XSL-FO The fo: tags are simply ignored Hello, Tom! Hello, Dick! Hello, Harry!

21 How is the resultant XSL-FO rendered in the browser? The browser cannot render XSL-FO The fo: tags are simply ignored We just see the included text Hello, Tom! Hello, Dick! Hello, Harry!

22 What went wrong? The problem is that web browsers do not have engines for rendering XSL-FO Instead, web browsers have engines for rendering HTML

23 So how do we render XSL-FO?

24 We need a different kind of program We need a program which contains an FO engine These programs are called FO processors Usually they also contain an XSLT engine They can generate various kinds of output, including PDF and image files

25 Generating XSL-FO from XML and then rendering the XSL-FO Apache FOP is a commonly-used FO processor fop contains both an XSLT engine and an FO engine Example usage on the cs1 server: cs1> fop -xml names2.xml -xsl names2.xsl -pdf names2.pdf This example command tells fop to apply an XSL stylesheet to an XML document and output a PDF file The XML file need/should not contain an xml- stylesheet instruction

26 Starting to write XSL-FO

27 First stage of an XSLT stylesheet for generating XSL-FO from XML

28 Contents of the fo:root element Element declaration: Thus, the minimum contents of an fo:root element are: fo:layout-master-set a description of the page layouts that are used in the document being specified fo:page-sequence+ a set of specifications for one or more sequences of actual pages in the document

29 Minimum fo:root element Example XSL-FO document … …

30 The layout-master-set Declaration in the unofficial DTD is Thus, the layout-master-set must contain at least one element of type fo:simple-page-master Example XSL-FO document … …

31 Page sequences refer to page masters Each page sequence must refer to a page master … …

32 How pages are modelled in XSL-FO In the XSL-FO page model, a page in the document being specified contains several areas The part of the page where the content will be placed is called the page- reference-area There are four margins around the page- reference-area These margins can be zero

33 How pages are modelled in XSL-FO (contd.) The page-reference-area can be divided into five regions Only the region-body is required Most content will be placed in the region-body The other regions may or may not be present If the other regions are not present, the regions-body will be the same size as the page- reference-area

34 How pages are modelled in XSL-FO (contd.) Unofficial DTD declaration for fo:simple-page-master is

35 How pages are modelled in XSL-FO (contd.) Unofficial DTD declaration for fo:simple-page-master is

36 How pages are modelled in XSL-FO (contd.) The definition, in the unofficial DTD, of the CSS-type margin properties is

37 How pages are modelled in XSL-FO (contd.) The definition, in the unofficial DTD, of the CSS-type margin properties is

38 Example XSL-FO document ......

39 The region-body element Declaration in the unofficial DTD is

40 The region-body element Declaration in the unofficial DTD is

41 The fo:page-sequence element Declaration in the unofficial DTD Thus a minimal fo:page-sequence must have a master- name and must contain an fo:flow

42 The fo:flow element Declaration in the unofficial DTD Thus a minimal fo:flow must have a flow-name (which specifies the region in which its content will be placed) and must contain at least one blocks entity The simplest instance of blocks is an fo:block element

43 The fo:block element Declaration in the unofficial DTD The simplest content for an fo:block element is just some text

44 Example XSL-FO document Hello world

45 Specifying lengths in XSL-FO A length in XSL-FO is written as a real number followed by a unit qualification Section of the XSL specification lists the allowable units as cm mm in pt (1/72 in) pc (12 pt) px em (size of capital M in current font size)

46 The fop processor accepts XSL-FO files as input Place the text on the previous slide in a file called demo.fo Then run the command fop -fo demo.fo -pdf demo.pdf A pdf file will be generated

47 The fop processor can output several types of file Assume that demo.fo contains the source code shown on the previous slide The command fop -fo demo.fo -png demo.png will output the document as png image To see the full range of file types that can be generated, run the command fop -out list

48 Using XSLT to generate XSL-FO Suppose we have the XML file shown Suppose we want to generate the XSL-FO for the PDF document shown Our XSLT program must –generate the "boiler-plate" XSL-FO when it finds the root node –and generate a sentence when it finds each country node We will need two templates

49 The "boiler-plate" template

50 The country template is a country.

51 The complete XSLT stylesheet is a country.

52 Using FOP Assume the XML file is called countries.xml Assume the XSLT file is called countries.xsl We can generate the PDF file thus fop -xml countries.xml -xsl countries.xsl -pdf countries.pdf We can see the XSL-FO thus fop -xml countries.xml -xsl countries.xsl -foout countries.fo

53 The XSL-FO that was generated France is a country. Germany is a country. Ireland is a country.

54 Block attributes In the unofficial DTD, many attributes are defined for blocks

55 Block attributes In the unofficial DTD, many attributes are defined for blocks We will consider just a a few at this stage

56 Block attributes In the unofficial DTD, many attributes are defined for blocks We will consider just a a few at this stage

57 A diagram of some block sttributes

58 Block attributes (contd.) Like a or a in HTML, a in XSL- FO specifies that some content should be displayed in a rectangular area that is visually separated by a new line Like a CSS area, an XSL- FO block area has attributes that we can control with CSS-like expressions However, XSL-FO provides many more attributes than CSS Before surveying all the attributes, let’s look at an example use

59 Example use of block attributes in XSLT is a country.

60 Example contd: the XSL-FO generated France is a country. Germany is a country. Ireland is a country.

61 PDF based on new XSL-FO output

62 Block area attributes (page 1) Block space-before and space-after –These specify minimum, optimum and maximum amounts of space that must be separate a block from the blocks just before and after the current block –Will be considered in detail later

63 Block area attributes (page 2) Block Margin –margin –margin-top –margin-bottom –margin-left –margin-right

64 Block area attributes (page 3) Block Border –Border style attributes: Overall border –border-style Side borders (Absolute Orientation) –border-top-style –border-bottom-style –border-left-style –border-right-style Sides borders (Orientation relative to writing-mode) –border-before-style (sometimes same as border-top) –border-after-style (sometimes same as border-bottom) –border-start-style (sometimes same as border-left) –border-end-style (sometimes same as border-right) –Possible values none | dotted | dashed | solid | double | groove | ridge

65 Block area attributes (page 4) Block Border (contd.) –Border color attributes: border-color border-before-color border-after-color border-start-color border-end-color border-top-color (sometimes same as border-before) border-bottom-color (sometimes same as border-after) border-left-color (sometimes same as border-start) border-right-color (sometimes same as border-end) –Possible values any predefined colour name rgb(0-255,0-255,0-255)

66 Block area attributes (page 5) Block Border (contd.) –Border width attributes: border-width border-before-width border-after-width border-start-width border-end-width border-top-width (sometimes same as border-before) border-bottom-width (sometimes same as border-after) border-left-width (sometimes same as border-start) border-right-width (sometimes same as border-end)

67 Block area attributes (page 6) Block Border (contd.) –Block Padding padding padding-before padding-after padding-start padding-end padding-top (sometimes same as padding-before) padding-bottom (sometimes same as padding-after) padding-left (sometimes same as padding-start) padding-right (sometimes same as padding-end)

68 Block area attributes (page 7) Block Border (contd.) –Block Background background-color background-image background-repeat background-attachment (scroll or fixed)

69 Specifying versus constraining properties Some properties, for example border-color, can specify an exact value which will appear in the output document However, the space-before and space-after properties can only constrain the set of possible values that will appear in the output document without being able to specify the exact value that will appear –The actual value will depend on the way that the FO engine handles conflicting constraints We will now consider these two properties in some detail

70 The space-before and space-after properties

71 Example XML document This is ex.xml. It contains a text element, which contains ten paragraph elements: This is a sentence in paragraph1. This is a sentence.... This is a sentence..... This is a sentence in paragraph10. This is a sentence.... This is a sentence. The next slide contains ex1.xsl, an XSLT stylesheet for processing this XML

72 ex1.xsl generates a header block and paragraph blocks Some text

73 Result of processing XML with ex1.xsl Result is a two page PDF file fop -xml ex.xml -xsl ex1.xsl -pdf ex1.pdf Notice that the sixth paragraph is split across the page boundary The block specifications do not require any space between the blocks Header block specification Some text Paragraph block specification

74 ex2.xsl Preventing paragraph blocks from crossing page boundaries Some text

75 Result of processing XML with ex2.xsl The entire sixth paragraph is now on the second page

76 The keep-together property This property has three components, referring to three different contexts –within-line, –within-column, –within-page Possible values –auto, which imposes no keep-together requirement –always, which always keeps the formatting object keep-together –, which imposes a keep-together requirement of the specified strength, with bigger integers being stronger if there is ever a conflict A description of how conflicts are resolved is given at

77 ex3.xsl Requiring space-before the paragraph blocks Some text

78 Result of processing XML with ex3.xsl The output now occupies 4 pages in PDF There is 4 cm of space before each paragraph –except for a paragraph at the start of a page Why is there no 4 cm space before a paragraph at the start of a page?

79 Space specifiers The space-before property specifies the space required before the area generated by an XSL-FO object The space-after property specifies the space required after the area generated by an XSL-FO object Each space-specifier has five components, with the default values indicated in parentheses –minimum (0 pt) –optimum (0 pt) –maximum (0 pt) –conditionality (discard) –precedence (0) A space specifier like space-before="4cm" is actually a shorthand for space-before.minimum="4cm" space-before.optimum="4cm" space-before.maximum="4cm" space-before.conditionality="discard" space-before.precedence="0"

80 The conditionality component of space specifiers Even if a space-specifier exists for an XSL-FO object, the space may sometimes not be rendered A space specifier is normally used to generate a space between the area generated by an XSL-FO object and the nearest visible mark on the page before of after that area The nearest visible mark may come from –the content of a non-empty content rectangle –a non-zero border the border need not belong to the next or previous area it could belong to an embracing block –some padding (because padding may contain background) the padding need not belong to the next or previous area it could belong to an embracing block If the area generated by an XSL-FO object is at the top of a page, there is no visible mark on the page before the area, so a space- before could be discarded Similarly, if the area generated is at the bottom of a page, a space- after could be discarded

81 Conditionality component of space specifiers (contd.) The conditionality component of a space specifier can have one of two values: discard this means that the space-before/after is not required if there is no visible mark on the page before/after the XSL-FO object which has this space specifier retain this means that the space-before/after must always be generated, even if there is no visible mark on the page before/after the XSL-FO object which has this space specifier

82 ex4.xsl Always requiring space-before the paragraph blocks Some text

83 Result of processing XML with ex4.xsl Now, there is a 4 cm space before each paragraph at the start of a page

84 Precedence of space specifiers Sometimes, when two boxes follow each other, the first box may have a space-after and the second box may have a space-after The formatting program does not automatically produce both of these spaces –the result would almost certainly be too much space between the boxes Instead, the formatting program uses space precedence rules to decide which space to generate on the page The value of the precedence component for a space specifier can be either – –or the word force By default, the precedence for a space specifier is 0 The space precedence rules are on the next slide

85 Space precedence rules When two space specifiers are in conflict, the following rules are used If either space precedence is force, the formatting program will generate a space equal to the sum of all specifiers with a precedence of force Otherwise, the formatting program will use the numeric space precedences to decide what to do If the specifiers have different numeric precedences, the specifier with the higher precedence is used If the specifiers have the same numeric precedence, –the formatting program will generate a space somewhere in the range [smaller-minimum, bigger maximum] –initially, the formatting program will try to generate a space equal to the bigger-maximum

86 ex5.xsl A force precedence wins Some text

87 Result of processing XML with ex5.xsl The 4cm space- before, with precedence=force beats the 8cm space-after There is a 4 cm space between each pair of paragraphs

88 ex6.xsl Two neighbouring specifiers with precedence=force Some text

89 Result of processing XML with ex6.xsl Both the 4cm space-before and 8 cm space-after have precedence=force Each pair of paragraphs on the same page are separated by 12 cm

90 ex7.xsl Two neighbouring specifiers with different numeric precedences Some text

91 Result of processing XML with ex7.xsl The 4cm space-before, with precedence=4, is beaten by the 8 cm space-after with precedence=5 Each pair of paragraphs on the same page are separated by 8 cm

92 ex8.xsl Two neighbouring specifiers with different numeric precedences Some text

93 Result of processing XML with ex8.xsl The 4cm space- before, with precedence=5, beats by the 8 cm space- after with precedence=4 Each pair of paragraphs on the same page are separated by 4 cm

94 ex9.xsl Two neighbouring specifiers with equal numeric precedences Some text

95 Result of processing XML with ex9.xsl Both the 4cm space- before and the 8cm space-after have precedence=4 The actual space must be in the interval [4,8] The larger optimum is 8cm, so it is tried It is possible everywhere, so it is used everywhere

96 A digression: the keep-with-previous and keep-with-next properties Each of these properties has three components, referring to three different contexts –within-line, –within-column, –within-page Possible values –auto, which imposes no keep-with-previous/next requirement –always, which always keeps the formatting object with the previous/next object –, which imposes a keep-with-previous/next requirement of the specified strength, with bigger integers being stronger if there is ever a conflict A description of how conflicts are resolved is given at

97 ex10.xsl Generating a space different from the optimum Some text

98 Result of processing XML with ex10.xsl Both the 4cm space-before and the 5-12cm space-after have precedence=4 The actual space must be in the interval [4,12] The larger optimum is 12cm, so it is tried everywhere However, the keep-together and keep-with-previous requirements mean that the optimum is possible only on the last page On the earlier pages, a smaller space is generated

99 ex11.xsl Using a negative space-before to cause overwriting Some text

100 Result of processing XML with ex11.xsl Each paragraph block, except that for paragraph 8, overwrites part of the previous block

101 ex12.xsl Conflict between negative and positive space Some text

102 Result of processing XML with ex12.xsl The first paragraph is moved back 8mm, because there is no space conflict However, when a sequence of two paragraphs are on the same page, there is a space conflict For space-before, max=-8mm forces minimum and optimum to be -8mm, because they cannot exceed the maximum For space-after, opt=4mm forces the max to be 4mm as well, because optimum cannot exceed maximum. Minimum is the default of 0. Space generated must be in range [smaller-min, bigger-max]; that is, in [-8mm,4mm] The bigger optimum, of 4mm is tried everywhere and can be used everywhere

103 ex13.xsl Another conflict between negative and positive space Some text

105 ex14.xsl Another conflict involving negative space Some text

106 A problem: the result of processing XML with ex14.xsl The processing by fop does not agree with what appears to be the rules The first paragraph should be moved back 8mm, because there is no space conflict However, when a sequence of two paragraphs are on the same page, there is a space conflict For space-before, max=-8mm should force minimum and optimum to be - 8mm, because they cannot exceed the maximum For space-after, opt=0mm should force the max to be 0mm as well, because optimum cannot exceed maximum. Minimum should be default of 0. Space generated should be in range [smaller-min, bigger-max]; that is, in [- 8mm,0mm] The bigger optimum, of 0mm, should be tried everywhere However,

107 A problem: the result of processing XML with ex14.xsl The processing by fop does not agree with what appears to be the rules The first paragraph should be moved back 8mm, because there is no space conflict However, when a sequence of two paragraphs are on the same page, there is a space conflict For space-before, max=-8mm should force minimum and optimum to be - 8mm, because they cannot exceed the maximum For space-after, opt=0mm should force the max to be 0mm as well, because optimum cannot exceed maximum. Minimum should be default of 0. Space generated should be in range [smaller-min, bigger-max]; that is, in [- 8mm,0mm] The bigger optimum, of 0mm, should be tried everywhere However, in all cases, -8mm is used Why? Dunno?

108 The Area Model

109 Almost everything in XSL-FO can be regarded as being placed in a rectangular box on the page –the page itself is a box –the regions with the page are boxes –the blocks within a region are boxes –each block contains boxes for lines –lines contain boxes for text and inline areas This nesting of boxes is called the Area Model

110 Box directions Earlier, it was said that –border-before-color is sometimes the same as border-top-color, –border-after-color is sometimes the same as border-bottom-color, –border-start-color is sometimes the same as border-left-color, –border-end-color is sometimes the same as border-right-color, –etc. These statements use the word "sometimes", because whether "before" means the same as "top", and so on, depends on the directions in which content is being added to a box Content is added to a box using two directions, which will be illustrated on the next few slides –the block-progression direction –the inline-progression direction

111 Box directions for normal Western text In normal Western documents, the block-progression direction is top-to-bottom, so –before means the same as top –after means the same as bottom

112 Box directions for normal Western text In normal Western documents, the inline-progression direction is left-to-right, so –start means the same as left –end means the same as right

113 Box directions for Semitic languages In Semitic languages, the block- progression direction is the same as in Western languages: top-to-bottom However, the inline-progression direction is right-to-left, so –start means the same as right –end means the same as left

114 One set of directions for Japanese Japanese can be written in various ways

115 One set of directions for Japanese Japanese can be written in various ways One possible way is to start at the top- right corner and write downwards –so the inline-progression direction is top-to-bottom so start means the same as top so end means the same as bottom

116 One set of directions for Japanese Japanese can be written in various ways One possible way is to start at the top- right corner and write downwards –so the inline-progression direction is top-to-bottom so start means the same as top so end means the same as bottom And then

117 One set of directions for Japanese Japanese can be written in various ways One possible way is to start at the top- right corner and write downwards –so the inline-progression direction is top-to-bottom so start means the same as top so end means the same as bottom And then move to the left for the next column of characters

118 One set of directions for Japanese Japanese can be written in various ways One possible way is to start at the top- right corner and write downwards –so the inline-progression direction is top-to-bottom so start means the same as top so end means the same as bottom And then move to the left for the next column of characters –so the block progression direction is right-to-left so before means the same as right so after means the same as left

119 Writing-mode The order in which a language appears on the page is called the writing-mode The writing-mode for English is left-to-right, top-to-bottom (lr-tb) Writing mode affects the direction of block-progression and inline- progression We can change these directions by using a style property called writing-mode The values defined in the XSL-FO specification are lr-tb | rl-tb | tb-rl | tb-lr | bt-lr | bt-rl | lr-bt | rl-bt | lr-alternating-rl-bt | lr- alternating-rl-tb | lr-inverting-rl-bt | lr-inverting-rl-tb | tb-lr-in-lr-pairs | lr | rl | tb The first letter-pair specifies the inline-progression direction The second letter-pair specifies the block-progression direction Not all of these writing modes are supported by all XSL-FO engines –for example, tb-lr gives an error message in Apache FOP The next dew slides show some example usage

120 We can set writing-mode in the simple-page-master tag Hello, Tom! Hello, Dick! Hello, Harry!

121 Writing-mode example 1

122 Writing-mode example 2

123 Page regions and box directions

124 A reminder: regions of a page Earlier, we saw that XSL-FO treats a page as a collection of regions But region-body is the only required region If we want to use the optional regions, we must define them in the order specified in this DTD element definition

125 The location of the regions The regions do not always appear on the page in the positions show here The locations shown here are simply those that the regions have in normal Western documents

126 Location of the optional regions in normal Western layout In normal Western documents, the writing-mode is lr-tb So before/after/start/end have the meanings shown in this image

127 Location of the optional regions in normal Western layout In normal Western documents, the writing-mode is lr-tb So before/after/start/end have the meanings shown in this image

128 Location of the optional regions in normal Western layout In normal Western documents, the writing-mode is lr-tb So before/after/start/end have the meanings shown in this image

129 Location of the optional regions in normal Semitic layout In normal Semitic documents, the writing-mode is rl-tb So before and after have the same meanings as in Western documents But the meanings of start and end are the reverse of their meaning in Western style documents

130 Location of the optional regions in normal Semitic layout In normal Semitic documents, the writing-mode is rl-tb So before and after have the same meanings as in Western documents But the meanings of start and end are the reverse of their meaning in Western style documents –the blue and red regions are reversed from the previous slide

131 Location of the optional regions in normal Semitic layout In normal Semitic documents, the writing-mode is rl-tb So before and after have the same meanings as in Western documents But the meanings of start and end are the reverse of their meaning in Western style documents –the blue and red regions are reversed from the previous slide

132 Western versus Semitic layout The before (green) and after (brown) regions are in the same place But the start (blue) and end (red) regions are reversed

133 Apache FOP cannot handle optional regions in Japanese layout We have seen that Japanese sometimes uses writing-mode=tb-rl Apache FOP seems able to handle the text placement But it does not seem able to handle the placement of the optional before/after/start/end regions

134 Margins and regions

135 body-region margins are measured from... When using the optional regions, it is essential to remember that margins for the content of the region-body are actually measured from the outside edges of

136 body-region margins are measured from... When using the optional regions, it is essential to remember that margins for the content of the region-body are actually measured from the outside edges of the page-reference-area

137 Margins and regions, Example 1

138 Margins and regions, Example 1 The simple-page-master margin surrounds the page-reference-area, which is divided into five regions

139 Margins and regions, Example 1 The simple-page-master margin surrounds the page-reference-area, which is divided into five regions In this example we have a zero margin in the simple-page-master –so, here, the page-reference-area covers the entire page

140 Margins and regions, Example 1 The simple-page-master margin surrounds the page-reference-area, which is divided into five regions In this example we have a zero margin in the simple-page-master –so, here, the page-reference-area covers the entire page The margin for the region-body pushes the content in from the outer edge of the page-reference-area

141 Margins and regions, Example 1 The simple-page-master margin surrounds the page-reference-area, which is divided into five regions In this example we have a zero margin in the simple-page-master –so, here, the page-reference-area covers the entire page The margin for the region-body pushes the content in from the outer edge of the page-reference-area The reason there is white space above and to the left of the content is that the region-body margin is wider than region-before and region-start

142 Margins and regions, Example 2

143 Margins and regions, Example 2 The page-reference area is smaller than the page, because the margin in the simple-page-master is greater than zero

144 Margins and regions, Example 2 The page-reference area is smaller than the page, because the margin in the simple-page-master is greater than zero The content is 3cm inside the edge of the page because –the simple-page-master margin is 2cm –the region-body also has a margin, of 1cm

145 Margins and regions, Example 3 Margins for region-body must exceed the extents of the region- before, region-after, region-start and region-end If not, the content of the region-body will appear in these other regions

146 More on writing-mode

147 Putting writing-mode in a different place We have specified writing-mode as an attribute of a simple-page- master element However, instead, we could specify it as an attribute of the region- body element

148 Writing-mode for region-body, Example 1 Notice that setting writing-mode in the region-body does not affect the placement of the other regions unlike setting writing- mode in the simple-page- master, which did affect all the regions

149 Writing-mode for region-body, Example 2

150 Where can writing-mode be specified? The XSL-FO specification says that a writing-mode can be specified for the following elements: fo:simple-page-master, fo:region-*, fo:table, fo:block-container, fo:inline-container However, not all of these element types are supported by all FO processors –For example, as of 2010, Apache FOP does not support fo:inline-container However, let's use it in fo:block-container

151 Using writing-mode in fo:block-container Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

152 Using writing-mode in fo:block-container Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

153 We can, of course, specify other attributes in fo:block-container Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

154 Now we can see why XSL-FO provides before/start/end/after

155 They let us specify style properties without worrying which writing-mode will be used Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

156 Now we can see why XSL-FO provides before/start/end/after They let us specify style properties without worrying which writing-mode will be used Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

157 Now we can see why XSL-FO provides before/start/end/after They let us specify style properties without worrying which writing-mode will be used Below, each block is given a border at the start of the text Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

158 Now we can see why XSL-FO provides before/start/end/after They let us specify style properties without worrying which writing-mode will be used Below, each block is given a border at the start of the text In normal Western documents, these borders will be at the left side Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

159 In Western documents start borders are at the left-hand side

160 But in Semitic documents start borders should be at the right-hand side

161 Why before/start/end/after are useful

162 We can specify style in a language- independent way Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

163 Why before/start/end/after are useful We can specify style in a language- independent way and then add writing-mode Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

164 Why before/start/end/after are useful We can specify style in a language- independent way and then add writing-mode Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick!

165 Static versus flow content The definition of fo:page-sequence in the unofficial DTD is The fo:title is intended for use in interactive user agents, so is not useful at present The fo:flow defines content which is often longer than would fit on one page, so it flows along a sequence of pages An fo:page-sequence can have several fo:static-content children fo:static-content elements are used to define content that appears in the same place on each page usually static content is placed in regions other than the region-body for example, static content is often used to define headers and footers for pages

166 Consider this two-page document Each page has three regions –region-body –region-before (silver) –region-start (grey/gray) The region-body contains flowing content The region-start is empty But the region-before has content –this content is the same on all pages –it is static content

167 Larger view

168 Specifying static content Greetings Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! Hello, Mick!.... Hello, Mick!

169 Location-dependent static content: page numbering Greetings Page Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! Hello, Mick!.... Hello, Mick!

170 Location-dependent static content: page numbering

171 Page numbering The page-sequence element has several attributes for page numbering In the unofficial DTD, this element's attributes are The attributes coloured red above control the values of the page numbers in the sequence The attributes coloured blue above control the appearance of the page numbers, –by controlling how these numbers are converted into strings

172 Specifying initial-page number Greetings Page Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! Hello, Mick!.... Hello, Mick!

173 Specifying initial-page number (contd.)

174 Specifying initial-page number (contd.) In the example just shown, we set the initial-page-number to a specified number However, initial-page-number can also have one of these symbolic values auto | auto-odd | auto-even The meaning of these depends on whether or not the current page- sequence is the first page-sequence in the document They will not be considered at this stage

175 Specifying the format for page numbers format="1" specifies that page numbers should be expressed in decimal notation and should use the minimum possible number of digits Example

176 Specifying the format for page numbers format="1" specifies that page numbers should be expressed in decimal notation and should use the minimum possible number of digits Example

177 Specifying the format for page numbers (contd.) format="0...1" specifies that page numbers should be expressed in decimal notation and should use at least the number of digits given Example

178 Specifying the format for page numbers (contd.) format="0...1" specifies that page numbers should be expressed in decimal notation and should use at least the number of digits given Example

179 Specifying the format for page numbers (contd.) format="i" specifies that page numbers should be expressed in lower-case Roman numerals Example

180 Specifying the format for page numbers (contd.) format="i" specifies that page numbers should be expressed in lower-case Roman numerals Example

181 Specifying the format for page numbers (contd.) format="I" specifies that page numbers should be expressed in upper-case Roman numerals Example

182 Specifying the format for page numbers (contd.) format="I" specifies that page numbers should be expressed in upper-case Roman numerals Example

183 Specifying the format for page numbers (contd.) Roman numerals can, of course, be used for large numbers Example

184 Specifying the format for page numbers (contd.) Roman numerals can, of course, be used for large numbers Example

185 Specifying the format for page numbers (contd.) format="a" specifies that page numbers should be expressed in lower-case Latin letters Example

186 Specifying the format for page numbers (contd.) format="a" specifies that page numbers should be expressed in lower-case Latin letters Example

187 Specifying the format for page numbers (contd.) format="A" specifies that page numbers should be expressed as upper-case Latin letters Example

188 Specifying the format for page numbers (contd.) format="A" specifies that page numbers should be expressed as upper-case Latin letters Example

189 Specifying the format for page numbers (contd.) Although it is rarely done, Latin letters can be used for large numbers Example

190 Specifying the format for page numbers (contd.) Although it is rarely done, Latin letters can be used for large numbers Example

191 Specifying the format for page numbers (contd.) The are three other number formatting attributes that we have not examined yet: letter-value ( auto | alphabetic | traditional ) #IMPLIED grouping-separator CDATA #IMPLIED grouping-size CDATA #IMPLIED The meaning of these three attributes is not yet implemented by Apache FOP So we will not consider them at this stage

192 Forcing page count The force-page-count attribute of a page-sequence element is used to impose a constraint on the number of pages in a page-sequence If this constraint is not satisfied, an additional page will be added to the end of the sequence –This page becomes the "last" page of the sequence The values that this attribute can have are even - force an even number of pages in this page-sequence odd - force an odd number of pages in this page-sequence end-on-even - force the last page in this page-sequence to be an even page end-on-odd - force the last page in this page-sequence to be an even page no-force - do not force either an even or odd number of pages auto - the meaning of this depends on whether or not the current page-sequence is the last page-sequence in the document; it will not be considered at this stage

193 Forcing page count, Example 1 This document really needs only two pages But it has three pages,... Because we forced the page count to be odd

194 Forcing page count, Example 2 This document really needs only two pages But it has three pages,... Because we forced the page count to end on an even number force-page-count="end-on-even" Since there are only two pages of content, we would still have needed only two pages But we had specified that the first page number should be 100

195 Accessing the current page number The element produces an inline-area whose content is the page-number for the page on which the inline-area is placed

196 Accessing the current page number The element produces some inline text representing the page-number of the page on which the inline text is located Greetings Page Hello, Tom! This is page Hello, Dick! This is page Hello, Harry! This is page Hello, Mick! This is page.... Hello, Mick! This is page

197 Accessing the current page number (contd.)

198 The text produced by the element depends on the page numbering format that is being used

199 Accessing the current page number (contd.) The text produced by the element depends on the page numbering format that is being used Greetings Page Hello, Tom! This is page Hello, Dick! This is page Hello, Harry! This is page Hello, Mick! This is page.... Hello, Mick! This is page

200 Accessing the current page number (contd.)

201 Cross-referencing pages

202 The last line of this document refers to the page containing the first line

203 Cross-referencing pages The last line of this document refers to the page containing the first line

204 Cross-referencing pages (contd.) The XSL-FO source-code for the document is shown below It will be explained on the next slide Greetings Page Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! Hello, Mick!.... Hello, Mick! Hello, Thomas! Are you related to Tom? (See page )

205 Cross-referencing pages (contd.) The important part of the source code is Hello, Tom!... See page The fo:page-number-citation element generates the cross-reference This element can be contrasted with the fo:page-number element as follows The fo:page-number element produces some inline text representing the number of the page on which the element itself is located (more precisely, the page containing the text generated by the element itself) The fo:page-number-citation element produces some inline text representing the number of the page which contains some other element (more precisely, the page containing the text generated by the other element) The other element is the element whose id attribute has a value equal to the value of the ref-id attribute of the fo:page-number-citation element

206 Using cross-referencing in the page footer (contd.) In the following document, each page has a footer of the form Page number1 of number2 The second number is generated by a cross-reference to the page containing the last text in the document

207 Using cross-referencing in the page footer (contd.) In the following document, each page has a footer of the form Page number1 of number2 The second number is generated by a cross-reference to the page containing the last text in the document

208 Using cross-referencing in the page footer (contd.) The source-code for the document is shown below Greetings Page of Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! Hello, Mick!.... Hello, Mick!

209 Multiple page masters

210 Until now, each document had only one simple-page-master This is because all our pages were intended to have the same layout However, frequently, we need to have different page layouts in a single document For example, if we are formatting a booklet which will be stapled, we will need to leave space for the stapling Left-hand pages will need a bigger margin on the right-hand side Right-hand pages will need a bigger margin on the left-hand-side

211 Multiple page masters Until now, each document had only one simple-page-master This is because all our pages were intended to have the same layout However, frequently, we need to have different page layouts in a single document For example, if we are formatting a booklet which will be stapled, we will need to leave space for the stapling Left-hand pages will need a bigger margin on the right-hand side Right-hand pages will need a bigger margin on the left-hand-side

212 Multiple page masters (contd.) The layout-master-set must contain a simple-page-master for each type of page payout that we need We will also need to specify when each of these simple page masters should be used This is done using a new type of element called a page-sequence-master Elements of this type are declared in the layout-master-set Remember that its definition in the unofficial DTD was So our layout-master-set will look something like this...

213 Multiple page masters: the leftPage ...

214 Multiple page masters: the rightPage ...

215 Multiple page masters: the page-sequence-master ...

216 fo:page-sequence-master Its definition in the unofficial DTD is The different types of child element for a page-sequence-master serve different purposes We need to specify when to use members of a set of alternative simple page masters So we need to use the child element called fo:repeatable-page-master-alternatives

217 The definition of this element in the unofficial DTD is We see that it can contain multiple children elements of type fo:conditional-page-master-reference Each of these specifies when to use a particular page master

218 fo:conditional-page-master-reference The definition of this element in the unofficial DTD is slightly wrong It should be This element specifies when a particular page master (identified by the master-reference attribute) should be used The other attributes describe the conditions that must be satisfied when the particular page master is used

219 Example page-sequence-master Suppose we want the first page to be a rightPage This means we want odd-numbered pages to use the rightPage master And even-numbered pages to use the leftPage master

220 Example page-sequence-master Suppose we want the first page to be a rightPage This means we want odd-numbered pages to use the rightPage master And even-numbered pages to use the leftPage master

221 The page-sequence Make the page-sequence refer to the booklet page-sequence-master Greetings Page Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! Hello, Mick!... Hello, Mick!

222 The result See that Page 1 is a rightPage and Page 2 is a leftPage

223 Including images

224 One way of including an image in a document is to use the fo:external-graphic element Its definition in the unofficial DTD is The graphic properties are:

225 Including images (contd.) Example usage content-width="99px" content-height="109px" />

226 Graphic inclusion, example 1 Greetings Page Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! … Hello, Mick!

227 Graphic inclusion, example 1 (contd.) Image in default position, at start/left side of block

228 Graphic inclusion, example 2 Greetings Page Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! … Hello, Mick!

229 Graphic inclusion, example 2 (contd.) Image aligned to end/right side of block

230 Images: floating The definition of XSL-FO includes various elements and attributes which are designed for floating parts of a document Unfortunately, these are not implemented in Apache FOP at present So, if you really want to wrap text around an image you must emulate floating by using tables or by using negative space- before

231 Graphic inclusion, example 3 Greetings Page This is a sentence. This is another sentence. This is another sentence. And this is another sentence. … And this is another sentence. Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! … Hello, Mick!

232 Graphic inclusion, example 3 (contd.) Negative space-before used to make text blocks “wrap” around image

233 Hotlinks

234 Hotlinks can be created by using the fo:basic-link element Its specification in the unofficial DTD is Either the external-destination and internal-destination should be specified. – If both are specified, the system may either report an error or use the internal-destination property

235 Hotlinks, example 1 Greetings Page Click-here-to-go-to-the-end-of-the-text Click-here-to-go-to-the-UCC-website This is a sentence. This is another sentence. This is another sentence. And this is another sentence. … And this is another sentence. Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! … Hello, Mick!

236 Hotlinks example 1 (contd.) Notice how the areas generated by the fo:basic-link elements - are inline areas and - have no decoration

237 Hotlinks, example 2 – highlighting links

238 Greetings Page Click here to go to the end of the text Click here to go to the UCC website This is a sentence. This is another sentence. This is another sentence. And this is another sentence. … And this is another sentence. Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! Hello, Tom! Hello, Dick! Hello, Harry! Hello, Mick! … Hello, Mick!

239 Hotlinks example 2 (contd.) The appearance of links below is like the default in HTML However, we can specify a completely different appearance if we wish

240 Tables

241 HTML versus FO tables HTML tables have this hierarchy XSL-FO tables have this hierarchy

242 Example table City Location Population Dublin East coast 1,200,00 Cork South coast 200,000

243 The result

244 Table properties

245 Lists

246 We create lists using the fo:list-block element Its specification in the unofficial DTD The specification for the fo:list-item is The specification for the fo:list-item-label is The specification for the fo:list-item-body is

247 List, example 1 Here is a simple list

248 List, example 1 Here is a simple list 1 Hello Tom! 2 Hello Dick!

249 List, example 1 Here is a simple list However, it is too simple, as the next slide shows 1 Hello Tom! 2 Hello Dick!

250 The layout is wrong

251

252 What's wrong? There are some attributes whose values we must consider Before we continue with lists, we should look again at the attributes that are defined for blocks

253 Block attributes (revisited) Here, again, are the block attributes in the unofficial DTD

254 margin-properties-inline

255 margin-properties-block

256 start-indent and end-indent The start-indent attribute of a block-area specifies the distance from the start-edge of the content-rectangle of the containing reference-area to the start-edge of the content-rectangle of the block-area The end-indent attribute of a block-area specifies the distance from the end-edge of the content-rectangle of the containing reference-area to the end-edge of the content-rectangle of the block-area

257 start-indent, example... Greetings Page This is an example sentence. This is another example sentence.

258 end-indent, example... Greetings Page This is an example paragraph....This is an example paragraph. This is yet another example paragraph....This is yet another example paragraph.

259 Indents for for list item labels and bodies The labels and bodies of list item can have indents This gives us four attributes for controlling layout

260 Example, to motivate producing "definition lists" Suppose we want to render some of its content as an XSL-FO list which looks like a HTML definition list

261 Example, to motivate producing "definition lists" Consider this XML document Suppose we want to render some of its content as an XSL-FO list which looks like a HTML definition list

262 Example, to motivate producing "definition lists" Consider this XML document Suppose we want to render some of its content as an XSL-FO list which looks like a HTML definition list Dublin East coast of Ireland 1,200,000 Cork South coast of Ireland 200,000

263 Example, to motivate producing "definition lists" Consider this XML document Suppose we want to render some of its content as an XSL-FO list which looks like a HTML definition list Dublin East coast of Ireland 1,200,000 Cork South coast of Ireland 200,000

264 Example, using FO lists to produce "definition lists" Dublin location: East coast of Ireland population: 1,200,000 Cork location: South coast of Ireland population: 200,000

265 Poor layout

266

267 "Definition" lists example (contd.) Let's add some background-color, to help see where we are Dublin location: East coast of Ireland population: 1,200,000 Cork location: South coast of Ireland population: 200,000

268 "Definition" lists example (contd.) Let's add some background-color, to help see where we are Dublin location: East coast of Ireland population: 1,200,000 Cork location: South coast of Ireland population: 200,000

269 The red areas are the list-blocks

270 "Definition" lists example (contd.) We can avoid the overlap by giving a start-indent to the bodies Dublin location: East coast of Ireland population: 1,200,000 Cork location: South coast of Ireland population: 200,000

271 "Definition" lists example (contd.) We can avoid the overlap by giving a start-indent to the bodies Dublin location: East coast of Ireland population: 1,200,000 Cork location: South coast of Ireland population: 200,000

272 A bit better, but not good enough Before After

273 "Definition" lists example (contd.) To avoid overlap, the bodies need a bigger start-indent Dublin location: East coast of Ireland population: 1,200,000 Cork location: South coast of Ireland population: 200,000

274 "Definition" lists example (contd.) To avoid overlap, the bodies need a bigger start-indent Dublin location: East coast of Ireland population: 1,200,000 Cork location: South coast of Ireland population: 200,000

275 No overlap, but perhaps the separation is too large?

276 Controlling layout of list items As we have seen, we can control the layout of list items by specifying the required indents for the labels and bodies of these items But this can require a lot of experimentation, especially with "definition" lists XSL-FO provides two functions to reduce the work These are –label-end(), used to compute the end-indent for labels –body-start(), used to compute the start-indent for bodies Let's try using body-start

277 "Definition" lists example (contd.) Using body-start to set the start-indent for the list item bodies Dublin location: East coast of Ireland population: 1,200,000 Cork location: South coast of Ireland population: 200,000

278 Better than nothing, but not good enough We need to use something else as well

279 Block attributes (revisited) Here, again, are the block attributes in the unofficial DTD

280 list-properties Here are the list-property attributes in the unofficial DTD The values of these attributes are used by label-end() and body- start() The initial value of provisional-label-separation is 6.0pt The initial value of provisional-distance-between-starts is 24.0pt

281 Computing label-end() and body-start() label-end() = width of the content-rectangle of the reference-area into which the list-block is placed - (the value of the provisional-distance-between-starts + the value of the start-indent + start-intrusion-adjustment - the value of the provisional-label-separation) of the closest ancestor fo:list-block body-start() = the value of the start-indent + start-intrusion-adjustment + the value of the provisional-distance-between-starts of the closest ancestor fo:list-block

282 "Definition" lists example (contd.) Setting provisional-distance-between-starts Dublin location: East coast of Ireland population: 1,200,000 Cork location: South coast of Ireland population: 200,000

283 The result

284 This works, but … The body-start() function worked but we still had to specify a value for provisional-distance-between-starts The main advantage is that we did not need to specify this value in each of the list item bodies –We need to specify it only once for each list-block But we still had to decide what the value should be and this required some experimentation, in order to find a distance which was long enough to prevent overlap with the longest label It would be better if we could automatically compute the required distance We can, indeed, automate the computation But it must be done in XSLT, at the time the XSL-FO document is being generated

285 A digression, back to XSLT

286 Computing required provisional-distance-between-starts for FO list blocks We need to compute a distance which will prevent overlap with the longest list-item-label Since list-item-labels are derived from the tag names in the source XML document, we need to compute the length of the longest tag name

287 Example XML document Consider this XML document Suppose we want to automatically compute the length of the longest tag name for the child elements of the elements The XSLT stylesheet on the next slide will do it Dublin East coast of Ireland 1,200,000 Cork South coast of Ireland 200,000

288 Example XML document Consider this XML document Suppose we want to automatically compute the length of the longest tag name for the child elements of the elements The XSLT stylesheet on the next slide will do it Dublin East coast of Ireland 1,200,000 Cork South coast of Ireland 200,000

289 Example XML document Consider this XML document Suppose we want to automatically compute the length of the longest tag name for the child elements of the elements The XSLT stylesheet on the next slide will do it Dublin East coast of Ireland 1,200,000 Cork South coast of Ireland 200,000

290 Example XML document Consider this XML document Suppose we want to automatically compute the length of the longest tag name for the child elements of the elements The XSLT stylesheet on the next slide will do it Dublin East coast of Ireland 1,200,000 Cork South coast of Ireland 200,000

291 XSL stylesheet to compute longest tagname maxLabelLength=

292 Unfortunately, … Unfortunately, there is a problem Apache FOP seems to have a bug in it The stylesheet shown on the previous slide is correct We can see this if we execute the stylesheet with another XSLT processor, the Saxon processor But Apache FOP does not execute it correctly We will see this on the next few slides

293 Executing the stylesheet with Apache FOP Assume the XML document is in a file called towns.xml Assume the XSLT stylesheet is in a file called towns.xsl Use Apache FOP to place the output in a file called towns.fo fop -xml towns.xml -xsl towns.xsl -foout towns.fo The resultant content in towns.fo is maxLabelLength=8 But this is wrong The longest tagname is population, which is 10 characters long However, there is nothing wrong with the stylesheet, as we can see if we execute it with the Saxon processor The result is shown on the next slide

294 Executing the stylesheet with Saxon Again, assume the XML document is in a file called towns.xml Again, assume the XSLT stylesheet is in a file called towns.xsl Use Saxon to place the output in a file called towns.fo java -jar /usr/local/saxon/saxon9he.jar towns.xml towns.xsl > towns.fo The resultant content in towns.fo is maxLabelLength=10 This is correct The longest tagname is population, which is 10 characters long

295 Using both Saxon and FOP Since there is an error in FOP, we could use Saxon and FOP together We could Saxon to generate an XSL-FO file from an XML file and an XSLT file java -jar /usr/local/saxon/saxon9he.jar towns.xml towns.xsl > towns.fo We could then use Apache FOP to generate a PDF file from the XSL-FO file which was created by Saxon fop -fo towns.fo -pdf towns.pdf

296 Back to generating XSL-FO lists

297 A stylesheet which calculates the max label length The next two slides provide an XSLT stylesheet which calculates the number of characters in the longest tagname It then specifies that number of em units as the provisional distance between starts The stylesheet uses three templates –One template generates the top-level structure of the XSL-FO document and calls a template which generates the XSL-FO output for each individual town –The template which generates the XSL-FO output for an individual town uses a third template to determine the provisional distance between starts which should be used in the list block for the town –The third template examines the does not consider the child when trying to determine the length of the longest child tag –Note that the second and third templates both match elements, but are distinguished from each other by having different mode attritbutes

298 A stylesheet which calculates the max label length The next two slides provide an XSLT stylesheet which calculates the number of characters in the longest tagname It then specifies that number of em units as the provisional distance between starts The stylesheet uses three templates –One template generates the top-level structure of the XSL-FO document and calls a template which generates the XSL-FO output for each individual town –The template which generates the XSL-FO output for an individual town uses a third template to determine the provisional distance between starts which should be used in the list block for the town –The third template examines the does not consider the child when trying to determine the length of the longest child tag –Note that the second and third templates both match elements, but are distinguished from each other by having different mode attritbutes

299 A stylesheet which calculates the max label length The next two slides provide an XSLT stylesheet which calculates the number of characters in the longest tagname It then specifies that number of em units as the provisional distance between starts The stylesheet uses three templates –One template generates the top-level structure of the XSL-FO document and calls a template which generates the XSL-FO output for each individual town –The template which generates the XSL-FO output for an individual town uses a third template to determine the provisional distance between starts which should be used in the list block for the town –The third template examines the does not consider the child when trying to determine the length of the longest child tag –Note that the second and third templates both match elements, but are distinguished from each other by having different mode attritbutes

300 A stylesheet which calculates the max label length The next two slides provide an XSLT stylesheet which calculates the number of characters in the longest tagname It then specifies that number of em units as the provisional distance between starts The stylesheet uses three templates –One template generates the top-level structure of the XSL-FO document and calls a template which generates the XSL-FO output for each individual town –The template which generates the XSL-FO output for an individual town uses a third template to determine the provisional distance between starts which should be used in the list block for the town –The third template examines the does not consider the child when trying to determine the length of the longest child tag –Note that the second and third templates both match elements, but are distinguished from each other by having different mode attritbutes

301 A stylesheet which calculates the max label length The next two slides provide an XSLT stylesheet which calculates the number of characters in the longest tagname It then specifies that number of em units as the provisional distance between starts The stylesheet uses three templates –One template generates the top-level structure of the XSL-FO document and calls a template which generates the XSL-FO output for each individual town –The template which generates the XSL-FO output for an individual town uses a third template to determine the provisional distance between starts which should be used in the list block for the town –The third template examines the does not consider the child when trying to determine the length of the longest child tag –Note that the second and third templates both match elements, but are distinguished from each other by having different mode attritbutes

302 Stylesheet, page 1 Towns Page

303 Stylesheet, page 2 em :

304 The resultant output Use Saxon to get the XSL-FO output Use fop to process the XSL-FO into PDF The result is shown below The separation is too long because we are using em units and this produces a length greater than that actually rendered for proportional fonts, in which different letters have different widths –Some people have introduced extensions to XSLT processors like Saxon in order to better estimate the actual rendered length of text –See, for example,

305 Another stylesheet which calculates max label length The next two slides provide a different XSLT stylesheet which calculates the number of characters in the longest tagname It differs from the previous one in that it assumes that all towns have the same set of child elements –so the length of the longest child tagname need be calculated only once, for the first town The stylesheet uses three templates One template generates the top-level structure of the XSL-FO document This calls another template which examines the first town, to get the length of the longest child tagname Then it calls yet another template which generates the XSL-FO output for each individual town This stylesheet actually generates exactly the same XSL-FO as the previous one The only difference is that it calculates the length of the provisional distance between starts just once, puts this value in a variable and passes it as a parameter to the template which processes individual towns

306 Another stylesheet which calculates max label length Towns Page em

307 Another stylesheet which calculates max label length :

308 Bulleted lists

309 "Bulleted" lists example Just using body-start; no usage of provisional-distance-between-starts Dublin • Location: East coast of Ireland • Population: 1,200,000 Cork • Location: South coast of Ireland • Population: 200,000

310 The result

311 A useful website See


Download ppt "XSL Formatting Objects XSL-FO. Why XSL-FO? Some History The history of HTML shows that, in the early days, both its designers and its users were confused."

Similar presentations


Ads by Google