Extensible Stylesheet Language (XSL) has been brought to the attention of a wide audience as a specification recommended by W3C on 15th October, 2001 for displaying and printing the XML document. The following is the general process to transform the XML document into XSL Formatting Objects (XSL-FO) and print it.
The knowledge about XSLT and XSL is necessary to develop XSLT stylesheet. The knowledge about XSLT and XSL is necessary to develop XSLT stylesheet. As for XSLT, many reference books has been published other than the specification. Probably, XSLT is already much more familiar one, since it is often used for the conversion from XML to HTML. The XSL specification has a huge amount of contents, it has over 400 pages. It is pretty hard to understand this specification. But basically it is intended for implementers. It is not necessary for XSLT stylesheet designers to understand everything. You can fully write stylesheet by knowing some regular contents and patterns.
This report explains how to edit stylesheet which is used for transforming XML documents into XSL-FO according to the example of
This report explains how to edit a stylesheet which is used for transforming a SimpleDoc document into XSL-FO. This report itself is the instance XML document of SimpleDoc.dtd, and it is then ready to be formatted by Antenna House
Now, what steps are necessary to develop XSL stylesheet? These steps are explained briefly as below.
Steps | Contents |
---|---|
Know the structure of the XML document | First, the information about the structure of XML source documents is required. XSLT processor can transform XML document into XSL-FO without a DTD. But the information described in the DTD such as types of elements, contents of elements, appearing order of elements and values of properties are necessary for developing a stylesheet. |
Specify a printing form | This is the printing form as a final output, in other words the output specification. XSL is a formatting specification. Printing forms has various range of specifications such as sizes and layouts of printing paper, layouts of head and body, deciding whether or not to output index, table of contents, and so on. |
Apply a printing form to formatting objects | After determining the specification of printing, you have to know what XSL formatting objects and properties are applied in order to print in this style. It is better to practice how to specify by referring to a simple stylesheet. |
Develop an XSL stylesheet | Put the instructions to the stylesheet in order to transform XML source documents into the target printing form. Map the XML source document to XSL formatting objects that can generate the output specification. The stylesheet have the similar aspect as the general programming languages, while it may be difficult if you do not understand the feature of the XSL. |
The following table shows the structure of SimpleDoc treated in this report. For more detail, refer to SimpleDoc.dtd.
Element | Meaning | Definition |
---|---|---|
a group of block elements | — | p | figure | ul | ol | dl | table | program | div |
a group of inline elements
|
— | a | note | span | b | i | em | code | br |
doc |
root element | (head, body) |
head |
header | (date | author | abstract | title)* |
date, author, abstract, title |
header elements, date, author, abstract, title |
(#PCDATA | a group of inline elements)* |
body | body | (chapter | part | section | a group of block elements | a group of inline elements)* |
part | part | (title, (chapter |a group of block elements | a group of inline elements)*) |
chapter | chapter | (title, (section | a group of bock elements | a group of inline elements)*) |
section | section | (title, (subsection | a group of block elements | a group of inline elements)*) |
subsection | subsection | (title, (subsubsection | a group of block elements | a group of inline elements)*) |
subsubsection | subsubsection | (title, (a group of block elements | a group of inline elements)*) |
title | title | (#PCDATA | a group of inline elements)* |
p |
paragraph | (#PCDATA | a group of block elements | a group of inline elements)* |
figure |
figure | (title?) Specify a file by the src property. |
ul |
unordered list | (li*) Specify a character for label of line by the type property. |
ol |
ordered list | (li*) Specify format of number in the label by the type property. |
dl |
definition list | (dt, dd)* Specify whether to format the block in horizontal way or in vertical way by the type property. |
dt |
definition term | (#PCDATA | a group of block elements | a group of inline elements)* |
dd |
description of details | (#PCDATA | a group of block elements | a group of inline elements)* |
table |
entire table | (title?, col*, thead?, tfoot?, tbody) Specify whether to make auto layout or fixed by the layout property. Specify the width of the entire table by the width property. |
col |
column format | EMPTY Speciry the number of the column by the number property, the width of the column by the width property. |
thead | table header | (tr*) |
tfoot | table footer | (tr*) |
tbody | table body | (tr*) |
tr | table row | (th | td)* Specify the height of the row by the height property. |
th | table header | (#PCDATA | a group of inline elements | a group of block elements)* Specify the number of the columns to be expanded across, the number of the rows to be expanded vertically by the colspan and rowspan properties. The align property allows horizontal alignment to be set to left, right, or center. The valign property allows vertical alignment to be set to top, middle, bottom or baseline. |
td | table data | (#PCDATA | a group of inline elements | a group of block elements)* Specify the number of the columns to be expanded across, the number of the rows to be expanded vertically by the colspan and rowspan properties. The align property allows horizontal alignment to be set to left, right, or center. The valign property allows vertical alignment to be set to top, middle, bottom or baseline. |
program | program code | (#PCDATA | title)* |
div | general block element |
(title, (general block element | general inline element)*)
The div element expands the type by the class property. |
a |
anchor(link) | (#PCDATA | a group of inline elements)*
Specify URL as the value of href property. |
note |
note | (#PCDATA | a group of inline elements)* |
b |
bold typeface | (#PCDATA | a group of inline elements)* |
i |
italic typeface | (#PCDATA | a group of inline elements)* |
em |
emphasis | (#PCDATA | a group of inline elements)* |
code |
program code of the in-line elements | (#PCDATA | a group of inline elements)* |
span |
general in-line element | (#PCDATA | a group of inline elements)* |
br |
line break
|
EMPTY |
The features of SimpleDoc are:
Now, we show the simplest simple stylesheet that transforms SimpleDoc to XSL-FO as follows.
The above XSL-FO is formatted/displayed as follows.
The above Simple.xsl and XSL-FO show the following facts:
XSLT processor loads the source XML document, starts processing from the root node. It finds the templates that match each node, and processes them as described in the templates. The processor processes child elements recursively, continues until the processor returns to the root element and there are no more templates to be processed.
Please note how the XSL stylesheet maps block elements and inline elements in source element to formatting objects.
Next, please pay attention to the XSL-FO tree structure. The following illustrates the structure of the XML document.
In contrast, the tree structure of XSL-FO is as follows. The root of the XSL-FO tree is fo:root, which has two children, fo:layout-master-set and fo:page-sequence. Fo:layout-master-set defines the page layouts and fo:page-sequence has a flow of contents arranged in in pages.
The following node of the fo:flow is the same tree structure as the original document though the element names has changed. The nodes existed in the original document are transferred as it used to be, using <xsl:template match="xxx">...<xsl:apply-templates;> The result has the same tree structure. In the Simple.xsl, the information described in <head>...</head> of source XML document is not output. It is because the child element <body>is specified to be applied but <head> element is omitted according to the instruction of <xsl:apply-templates select="body" />
We can get only a simple output when an XML document is processed according to the sample in the previous chapter. In order to get more rich outputs, we add the following specification.
Item | Specification |
---|---|
Paper size | Letter size (8.5in x 11in) |
Orientation | Portrait |
Writing mode | lr-tb |
Organization | cover, table of contents, the text, and index are proceseed in order from the top. |
Header, Hooter | Specify the header, footer regions. Do not set text inside the whitespace on the both side of the body. |
Item | Specification |
---|---|
Margin of paper | Top: 25mm, Bottom: 25mm, Left: 25mm, Right: 25mm |
Item | Specification |
---|---|
Margin | Margin top: 20mm, bottom: 20mm, left: 0mm, right: 0mm |
Content | Consists of head, table, list, paragraph and image. |
Writing mode | lr-tb |
Column | 1 |
Default font size | 10pt |
Text align | justify |
Other conditions | Place a header region and a footer region. The content of the footer region is fore-edge justified and changed by right and left pages. Place a borderline between a footnote region and a body region. The borderline is a solid, the length is one-third of the region body, left justified. |
Item | Specification |
---|---|
Extent | 10mm |
Writing Mode | lr-tb |
Content |
Print the title
Font size is 9pt. Center aligned in the inline progression direction, bottom aligned in the block progression direction. Create an index on the upper part of a page. |
Item | Specification |
---|---|
Extent | 10mm |
Writing Mode | lr-tb |
Contents | Print a page number and a sub-title of the current page on the fore-edge side. |
Item | Specification |
---|---|
Margin | Margin top: 25mm, bottom: 25mm, left: 25mm, right: 25mm |
Column | 2 |
Column rule | 20mm |
XSL Stylesheet consists of the following 5 files.
File Name | Contents/Usage |
---|---|
|
Main body of the XSL Stylesheet |
|
The file which defines the property of XSL-FO collectively. |
|
The file which defins values, such as paper size, as a parameter. |
|
The file which defines the processing of creating an index collectively. |
|
The stylesheet for a document format without a cover, a table of contents and an index. |
SD2FO-DOC.XSL consists of the following top level XSL elements.
XSL elements | Contents/Usage |
---|---|
|
|
|
Specifies the value of paper size, etc. in the whole stylesheet as a parameter. |
|
Groups and defines the property, such as block and inline, for every object of XSL-FO to output. |
|
Defines the template for transformation described to every element of an XML document ("xxx"). It is called by <xsl:apply-templates /> |
|
A subroutine of templates which is explicitly invoked by <xsl:call-template name="yyy"/> |
|
Generates a key for an index. How to make an index is explained later in this document. |
xsl:param and xsl:attribute-set are defined in param.xsl and attribute.xsl respectively, and are included in SD2 FO-DOC.XSL.
xsl:param and xsl:attribute-set are not necessarily required, but they have the following advantages:
From here, the stylesheet is explained along with this SD2 FO-DOC.XSL.
The page layout of SD2 FO-DOC.XSL has the following features:
Therefore, 5 types of page layouts, a cover, a table of contents, the text (left), the text (right), and an index are required. The definition method of each page layout is described henceforth.
Page layout of Cover/Teble of contents is shown as follows:
The page layout is defined as
Although the specified value is the same, the page master is prepared for each considering the possibility of any changes.
Master name properties of fo:simple-page-master are set as follows:
master-name | Usage | Refered Template |
---|---|---|
PageMaster-Cover | For a cover | <xsl:template match="doc/head"> |
PageMaster-TOC | for a table of contents | <xsl:template name="toc"> |
The next figure shows the XSL-FO tree structure in the site of where to define these page masters and where to refer to.
In this document, the page layout changes by right and left page. In XSL-FO, the layout change on right and left page can be made by grouping the
Create two fo:simple-page-master, one for left pages and another for right pages, and groups them by
It is described in the stylesheet as follows:
The page layout of an index is two-column layout. In XSL-FO, the number of column is specified to the
The templates that process the doc elements created according to the requirement for processing conditions are shown below. As required they are creaged in order of fo:layout-master-set outputs, a front cover, a table of contents and the body text. It is possible for the attributes of doc elements to control whether to make these or not. It is possible to control whether to output a cover/a table of contents or not by specifying the properties of the doc element or the external parameters. For example, a cover is not outputted by specifying <doc cover="false">. A table of contents is not outputted by specifying 'false' to the value of toc-make.
The cover is created by the templates that process the head.
The layout specification of a title portion is arranged by the portion of name="cover.title" in xsl:attribute-set.
Followings shows the point which should be aware of:
If the logo attribute is specified to the author, it is rendered as the image. This is processed by the author.logo.img template. The pos attribute specify to put the image on the left or top of the author. The example of an author name with a picture may be shown at the cover of this document.
The template structure is very simple. xsl:use-attribute-sets calls a group of properties defined by the xsl:attribute-set element and applies them to fo:block-container that matches to each title, date and author. In each fo:block-container, each template is applied to each element of title, date, and author.
A table of contents is created by the toc template. The toc template is called from the templates that process the root elements doc, by using <xsl:call-template name="toc">
The toc template processes a table of contents in the following order.
This template is called from the template that processes the doc elements. So, "current node" is the doc element node. xsl:for-each change this
The toc.line template creates a line of contents
The toc template processes a table of contents in the following order.
The nest level can be counted as follows: count(ancestor-or-self::part | ancestor-or-self::chapter | ancestor-or-self::section | ancestor-or-self::subsection | ancestor-or-self::subsubsection). In other words, count itself which is a child of the doc elemnet or the ancestor nodes. This chart is shown below:
Set fo:block properties according to the nest level of the current node. Note that in this case, the properties are not set according to the element such as part, chapter, section, subsection. By setting properties according to the nest levels, the table of contents can be generated without depending on the elements used, but using the same format. Next table shows the properties set in the stylesheet.
Property | Nest level | ||||
---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | |
margin-left | 0em | 1em | 2em | 3em | 4em |
space-before | 5pt | 3pt | 1pt | 1pt | 1pt |
font-size | 1em | 0.9em | 0.9em | 0.9em | 0.9em |
font-weight | 700 | 600 | 500 | 400 | 300 |
You have to create page numbers that show the page where each part, chapter, section, subsection appear. Page numbers cannot be fixed until the Formatter finishes formatting the XSL-FO instance.
In order to solve this problem, XSL-FO provides the function fo:page-number-citation. XSL Formatter replaces
In the template, the
Use fo:leader between the title of the contents and the page numbers. fo:leader is a special object for generating inline area. In the example, leader-pattern="dots" is specified. It plays the role to fill the space between the title and the page number.
It is important that text-align-last="justify" in fo:block specifies to justify the entire line. So, the titles are left-justified and the page numbers are right-justified, then the
fo:leader property can specify various patterns as shown below. fo:leader properties are written in the left side.
The following pattern can also be specified.
Shown below is an example of toc created by taking the steps described.
See the table of contents in this report for an output example.
The body in the XML source document is contained to the descendants or self of the
This template pocesses the body elements as shown below.
A page header and a page footer are described in fo:static-content. In the body page, in order to change the page layout on right and left pages, four fo:static-content should be prepared which are used for the right and left pages of the footer, and for the right and left pages of a header. Moreover, the border between the text and a footnote is created using also fo:static-content.
Four of fo:static-content are mapped to the region of a page as follows. The layout for right and left pages are defined in fo:simple-page-master of the body, which is prepared by the "Body - Change Page Layout on Right and Left pages " section in this document, then the header region and footer regions of each page are named, respectively. On the other hand,
Page | Name of region | Name of static-content |
---|---|---|
Right page heade | fo:region-before region-name="Right-header" | fo:static-content flow-name="Right-header" |
Right page footer | fo:region-after region-name="Right-footer" | fo:static-content flow-name="Right-footer" |
Left page header | fo:region-before region-name="Left-header" | fo:static-content flow-name="Left-header" |
Left page footer | fo:region-after region-name="Left-footer" | fo:static-content flow-name="Left-footer" |
The border between a footnote and the text is created by fo:static-content with flow-name called xsl-footnote-separator. The fo:leader object is used for drawing a line. One third of the width of the body region is secured as a solid line.
The content of the body is outputted as a child of fo:flow.
It is possible to set up the initial value of a page number using the
The contents of a page footer are outputted to fo:static-content. The contents are the same although the arrangement differs on a right and left page.
The title of the section in a document is outputted to a page footer. Since the title of section changes for every paragraph, it serves as a running footer. For this reason, fo:marker and fo:retrieve-marker are used.
Specify the class name of fo:marker you want to replace with the retrieve-class-name property belonging to fo:retrieve-marker. retrieve-boundary specifies a range of appliance. retrieve-position specifies which fo:marker in the page should be sellected. (What appeared first or what appeared last, for example)
Generates fo:marker against the title element in the text. It is described as follows in the template which processes "part | chapter | section | subsection | subsubsection | appendix."
Hereby, whenever a section appears in a document, fo:marker is generated as follows.
The contents of a page header are the following two.
The processing for outputting a title to a page header is only to output the title element to fo:block as follows.
It's also possible to output a thumb index to a page using fo:marker and fo:retrieve-marker like the section title of a page footer. In SD2 FO-DOC.XSL stylesheet, 15 types of class names (thumb1, thumb2, ..., thumb14, and thumb0) are prepared and set to the objects which appear in a document (the top level object among part/chapter/section) in order. Each fo:retrieve-marker is set to fo:static-content which is a page header using a table cell. fo:retrieve-marker is not replaced if fo:marker which corresponds in a page does not exist. Thereby, the thumb index can be seen as moving according to the change of a section.
A table model for creating the page header in the stylesheet is as follows:
In processing "part | chapter | section | --" in the text, the generation of fo:marker is shown as follows. The element name which changes a thumb index is set to Variable thumb ($thumb). Since it is the template which is common and processes two or more elements, you have to judge a current node. Using local-name(), the element name of a current node is investigated.
As for the class name (marker-class-name), 'thumb' is set asa fixed character sequence, then a number is given in order after that. In order to begin from 1 and to repeat per 15 pieces, the element obtains first what position it is as compared with the same element in a document using xsl:number. Next, the number given to the class name is realized by using the number of the remainder after deviding the position figure by 15.
Generally the style of the head is made according to the part, chapter, section, subsection and subsubsection elements, but in this case it is made according to the nest level. The conditions to be set are shown below.
Nest level | attribute-set | Style conditions |
---|---|---|
1 | h1 |
font: size 24pt, sans-serif, Bold
space-after: 14pt, bottom border: solid 2pt, break condition: break-before="page" |
2 | h2 |
Font : size 16pt, sans-serif, bold
space-before: 19pt, space-after: 5pt, keep-with-next. within-page: always |
3 | h3 | font: size 13pt, sans-serif, bold
space-before: 14pt, space-after: 5pt, keep-with-next. within-page: always |
4 | h4 |
font: size 12pt, sans-serif, bold space-before: 5pt, space-after: 5pt, keep-with-next. within-page: always |
5 | h5 |
font: size 10pt, sans-serif, bold space-before: 3pt, space-after: 3pt, keep-with-next. within-page: always |
These conditions of style are defined in the following stylesheet.
keep-with-next.within-page="always" is specified to heads in order to avoid breaking pages before the next block. It is not specified in h1, instead, break-before="page" is specified. So the page break is inserted before h1 block, it is kept at the top of the following page and is kept with the next block naturally.
Templates that process the heads are shown below. Heads are processed in one template intensively because the styles are selected according to the nest level.
The stylesheet that processes heads consists of four templates. Actual title of the head is created form the title.out template. The title.out template processes heads in the following order:
Although the template which processes 2nd part/title - subsubsection/title is "empty processing" (nothing is outputted), this is an usual practice for not outputting a title doubly.
The title line is outputted by the title.out template as shown proeviously. However the title character sequence will be outputted again because the title element appears while xsl:apply-templates processes the part/title - subsubsection/title elements. However, if the template which matches part/title - subsubsection/title is prepared and the contents are empty, the output of an excessive title character sequence can be controlled.
Shown below is an example of a generated title by taking previous steps. Note that the result of
It is very easy to transform b(bold), i(italic), em(emphasis), code(inline program code) into formatting objects. The templates create fo:inline template and set attributes to be applied. Bold is set as font-weight="bold", italic is font-style="italic", em also maps to bold. The way is different from the b but it becomes the same result. Code sets monospace to font-family property.
As fo:inline is applied, the line is not considered to break at the last of text. The example is shown below.
The inline element i becomes [ italic].
The inline element b becomes [ bold typeface ].
The inline element em also becomes [ bold typeface ].
The inline element code (inline program code) becomes [
monospace font (apply monospace font)
].
The
The example using this stylesheet is as follows:
'This example is shown on the Web<a href="http://www.w3.org/"> at the site of W3C</a>'.
is shown as:
'This example is shown on the Web at the site of W3C
.'
'This example is shown on the Web site at <a href="http://www.w3.org/">http://www.w3.org/</a>.'
is shown as:
'This example is shown on the Web site at http://www.w3.org/
'
'This example is shown on the Web site at <a href="http://www.w3.org/">http://<em><i>www</i>.<i>w3</i>.<i>org</i></em>/</a>.'
is shown as:
'This example is shown on the Web site at http://www.w3.org/.'
Although the anchor was changed into the simple text here, in SD2 FO-DOC.XSL, the
The
fo:footnote object in the XSL generates a footnote and a
Shown below is a typical fo:footnote object.
Generally, the same label as the footnote citation in the text is placed before the footnote text, and a footnote citation is usually a sequence of numbers. These characters must be generated in the stylesheet. Formatting object does not have the function to achieve these. The following shows the stylesheet processing.
xsl:number is an XSL processing instruction.
<xsl:number level="any" count="//note" format="(1)" />
searches all the descendant of the note elements under the root element in appearing order, finds out the same element as the current note element and formats the appearing number as described in "(1)",
baseline-shift="super" shifts the baseline to the default position for superscripts. Below shows the example of footnote.
"This is an example of footnote. Place a footnote here. <note> This is a footnote text. It is placed at the lower end of the body resion and separated from the text part.</note>"
is expressed as:
"This is an example of footnote. Place a footnote here.
The br element is an empty element, so it is replaced by an empty fo:block element. Then the line bleaks.
The following table shows the example of the process.
"In the paragraph, put <b> forcibly <br/> break a line </b> because the paragraph is not finished, the property set before the line break can be used."
is expressed as:
"In the paragraph, put
forcibly
break a line
because the paragraph is not finished, the property set before the line break can be used."
The span attribute (general inline element) is only transformed into fo:inline. It can be extended if any instructions are defined for the class attribute
The processing of the block elements except tables and lists (ol,ul,dl) are explained in this chapter.
The p element (paragraph) is frequently used. The following shows the template processing the p element.
The templates are simple, and is only to transform into fo:block. The indent in the beginning of the line is specified by text-indent, the line justification is specified by text-align. And specify keep-together to keep a paragraph within one page.
This is the case that one line has the width of 21em.
In case that one line has the width of 25em.
Figure elements are transformed into
fo:external-graphic is generated and path of the figure is specified by the src property of the figure element. In case the size of the figure is specified by the width, height attributes, put them in
Program elements (Program code) are transformed into fo:block and display the fonts in monospace. The following shows the templates.
The program element and the p element has the common point that both generate fo:block in the template. But the difference is that the program element process only text(). There are no templates to process text nodes (match="program/text()"). So they are processed by the built-in template in XSL in order to process only the text node. The following are important properties that apply to fo:block.
According to these specifications the text in the program element is formatted as pre-formatted text.
The div element(general block element) simply transforms into fo:block with no properties. The templates are shown below.
You may change this template as you desire. The example of applying the div element is as follows. This sample stores formatting object directly to the div element and output it.
The template specifies to copy all the descendants of the div element directly to the output by <xsl:copy-of select="node()" />. In order to use this function, you must specify following fo namespace to the doc element.
Below shows how to use.
It is shown as follows:
In order to process the descendants of the table element and generate a table, it should be transformed into fo:table-and-caption formatting object. Let us compare the SimpleDoc table with XSL table. First of all, the SimpleDoc table is as follows:
Element | Meaning | Definition |
---|---|---|
table |
entire table | (title?, col*, thead?, tfoot?, tbody) Specify whether the table layout is formatted automatically or it is fixed, in the layout property. The entire width is specified in the width property. |
col |
column property | EMPTY The column width is specified in the width property, the column number is specified in the number property. |
thead | table header | (tr*) |
tfoot | table footer | (tr*) |
tbody | table body | (tr*) |
tr | table row | (th | td)* The height of the row is specified in the height property. |
th | table header cell |
(a group of inline elements)*
The number of the rows to be expanded across is specified in the colspan property, the number of the rows to be expanded down is specified in the rowspan. The align, valign propertys allows horizontal, vertical alignment to be set. |
td | table data cell | Same as the definition of th |
On the other hand, the object of the table of XSL-FO has the following composition.
Element | Meaning | Definition |
---|---|---|
fo:table-and-caption | entire table and caption | (table-caption?, table) |
fo:table-caption | caption of the table | (%block;) |
fo:table | entire table (except caption cells). | (fo:table-column*, fo:table-header?, fo:table-footer?, fo:table-body+) table-layout : Specify automatically table layout or fixed layout. table-omit-header-at-break : Specify whether to omit placing header or not when the page breaks. table-omit-footer-at-break : Specify whether to omit placing footer or not when the page breaks. |
fo:table-column | table column | EMPTY column-number : The number of columns column-width : The width of the column |
fo:table-header | table header | (fo:table-row+ | fo:table-cell+) |
fo:table-footer | table footer | (fo:table-row+ | fo:table-cell+) |
fo:table-body | table body | (fo:table-row+ | fo:table-cell+) |
fo:table-row | table row | (fo:table-cell+) |
fo:table-cell | Table cell | (%block;)+ number-columns-spanned : The number of columns spanned by table-cells. number-rows-spanned : The number of rows to be spanned. |
Comparing these two, they have almost the same structure. Transforming into tables is basically considered to exchange the structure to another.
Templates that process tables are shown below.
The stylesheet looks long, though, it is only to map the element name of the SimpleDoc to that of XSL formatting object. Below shows the points.
Below is an example of table construction.
If nothing is specified, the table width will be divided by the number of columns and the width of the column will be given equally.
Symbol | How to read | Meaning |
---|---|---|
| | vertical bar | Means one element or another is to be used. |
? | question mark | Means that the element appears zero or one time. |
, | comma | Means that elements appear in the same order in that element inside the document. |
* | asterisk | Means that the element appears zero or more times. |
+ | plus | Means that the element appears one or more time. |
( ) | parentheses | Means to group plural numbers of elements in the parentheses. |
empty | Means that only one element can be described. |
Specify the column width by the col element. Set 10%, 20%, 40% from the left. Contents in the table header cells are center-aligned. Contents in the first and the second columns from the left are center aligned, center valigned by specifying valign="center" align="center"
Symbol | How to read | Meaning |
---|---|---|
| | Vertical bar | Means one element or another is to be used. |
? | question mark | Means that the element appears zero or one time. |
, | comma | Means that those elements appear in the same order in that element inside the document. |
* | asterisk | Means that the element appears zero or more times. |
+ | plus | Means that the element appears one or more time. |
( ) | parentheses | Means to group plural numbers of elements in the parentheses. |
empty | Means that only one element can be described. |
When you specify the vertical alignment in the cell of the table, be sure of the following point. vertical-align can be specified in HTML, vertical-alignment can be specified in CSS2, however, the property which corresponds to this in XSL becomes
In SimpleDoc, three list elements with which the format of the label portion of an item differs, a list with (1) number (ordered list), a (2) numbers-less list (unordered list), and (3) definition type list
In order to put the list elements to both the label of the list and body of the list, it is neccessary to transform them to fo:list-block in XSL. Let us compare lists of SimpleDoc with those of XSL formatting objects.
Element | Meaning | Definition |
---|---|---|
ol | ordered list | (li)* |
ul | unordered list | (li)* |
li | list item | (a group of inline elements)* |
dl | definition list | (dt, dd)* |
dt | definition term | (a group of inline elements)* |
dd | definition details | (a group of inline elements)* |
On the other hand, the list of XSL-FO has the following structure.
Element | Meaning | Definition |
---|---|---|
list-block | formatting object that formats lists | (list-item+) provisional-distance-between-starts : Specify the distance between the start indent of the fo:list-item-label and the start indent of the fo:list-item-body. provisional-label-separation : Specify the distance between the end of the list-item-label and the start of the list item body. |
list-item | list item including list label and list body. | (list-item-label,list-item-body) |
list-item-label | label of a list item. | (%block;)+ |
list-item-body | body of a list item | (%block;)+ |
Both correspondence relation is shown in a figure.
The followings are remarkable differences between two.
Each template is explained below:
When formatting a list, it is important to position the label and the body. In the fo:list-block:
The template sets these values to the startdist, gap attributes of the ol element. But actually the list-item-label and list-item-body are specified as descendants of the fo:list-item. In order to specify the position of the end of the list-item-label and the start of the list-item-body, the label-end(), body-start() functions are used in the template.
body-start() = (start-indent of the label) + (provisional-distance-between-starts)
These function specification is just a manner. If you understand how to layout lists, it may be no problem to apply these mechanically.
The list label consists of a sequence of numbers. A sequence of numbers is generated by the default <xsl:number format="1."/>.
The label format is specified with the type property of the ol element. For example, the label (01), (02), (03)... will be generated if type="(01) is specified . The following formats can be used for a number portion.
Form | Output |
---|---|
1 | 1, 2, 3, 4... |
01 | 01, 02, 03, 04... |
a | a, b, c, d,...x, y, z, aa, ab, ac... |
A | A, B, C, D,...X, Y, Z, AA, AB, AC... |
i | i, ii, iii, iv, v, vi, vii, viii, ix, x,... |
I | I, II, III, IV, V, VI, VII, VIII, IX, X,... |
The type property specifies UNICODE characters that represent zero, 1 and punctuation marks such as parentheses. As the label formatcan be specified in the XML source document, the document can be made flexibly.
Following is the output result.
The difference between the ol and ul templates is only label processing. In the case of unordered list, the characters are set in the label. Types of characters can be specified in the type property in the ul element.
Next template is an example of the template that place an image as a character for label of line. Specify the image file by img:file name in the type property defined for the ul element.
XML source data
Folowing is the output result
XML source data
Folowing is the output result
The following problem occurs when transforming the definition list into fo:list-block formatting object.
It is better to be able to process definition list like HTML also in XSL. But the above two problem cannot be solved by the data driven stylesheet which process the tags in the XML source document in appearing order. It is necessary to find a pair of dt, dd in the XML source document. Following is the template that realize this process. The template is a remodel of the sample XSL stylesheest described in the XSL specification.
In this stylesheet, you have to determine which transformation to use from the following type by the type attribute defined for the dl element:
When "list" is specified in the type attribute, select the first one.
In case of the list type, after generating fo:list-block, the process.dl.list template will process these. The process.dl.list template processes the following:
The following is a sample XML source data of definition list.
The following figure shows how fo:list-item is generated from the dt, dl. fo-list-item #1-n is generated from the first dl. #2-n is generated from the nested dl.
The process.dl.list template calls itself recursively. In the general programming language, it is natural to assign a value to a variable and process using a variable. But in XSL, it is impossible to assign a value to a variable, but it is possible to initialize a value instead. Loops are formed by taking recursive process.
For HTML type, the dl.format.block template transforms. Only the template have to do is to call the descendant templates in order to process dt, dd in appearing order.
The following is the output of list type transformation. To make it look better, fo:list-item-label and fo:list-item-body are bordered.
The following is the output of HTML type transformation.
With XSL Formatter, the following relates with PDF generation are available.
Although some of the functions described here in creating PDF are not defined in the specification of XSL-FO V1.0, it's possible by using
Although the document information cannot be set up by XSL-FO V1.0 specification in case a formatted result is outputted to PDF, it's possible to set up the document information by Antenna House extension specification. The definition is given using
PDF bookmarks use
The element with the name element as a reference destination is processed as an inline object which has id as follows.
Moreover, it is also possible to set a link to the portion where it corresponds in a document from a table of contents or an index. In this case, id used for reference creates id automatically using the generate-id() function. When the generate-id() function is called, XSLT processor will create a suitable character sequence like "IDXP83DL" corresponding to a current node for id.
In the case of a table of contents, the portion which outputs an item by the toc.line template is described as follows.
Set id using generate-id() also when outputting a title in the text used as the reference destination. The value of id generated by the generate-id() function is always the same among the same elements, and surely different against different elements.
Create an appendix list in the end of the book, and make it possible to refer to the appendix at the end of the book by the data numbers in the text. Even if it generates these data numbers automatically and revises the appendix list, it is made not to need to update the reference numbers in the text while editing.
The whole appendix list is expressed with the
The appendix is referred by the ref element, ref-id="xxx "in the text. (xxx is the id value of the li element of the reference destination.) The stylesheet which generates this reference label is as follows.
Since the reference destination of the ref element shows the turn of the li element in the bib element, then the position() function calculates what number the li element comes whose value of ref-id matches in the bib element.
Here in this section, the creation method of an index is explained sequentially. The templates for indexes are put together in index.xsl. For more details, see also the contents of index.xsl.
The index element is defined by SimpleDoc for the items put on an index.
Declare the key with a name using xsl:key in order to group the index elements by using the beginning of the character.
Since
Creation of an index is started from the index.create template in the index.xsl stylesheet. Like other pages,
Next, the index elements for numbers and alphabets are processed.
"index.create.mainALPHA" is the template which generates the index of alphabets. The following shows the examle using "index.create.mainALPHA"
What is considered to be difficult in creating an index is to group the target nodes and take them out. In order to group them, xsl:key which is mentioned above and the data in the head of index.xsl are used.
Each alphabet character is defined as an entity and it is used for grouping. Characters are taken out one by one from the entity, and then the node set which has the character as a key is taken out.
In the portion (1), one character used as a key is passed to the "index.create.section" template as a parameter, and a node set is processed in the "index.create.section" template. In (2), the following one character is taken out and all characters are processed by calling "$remainderALPHA" recursively by (3).
The "index.create.section" template outputs a node set which has a character used as index-key.
By using the
The
The original version of this tutorial was written in Japanese for XSL School, June 2001, Tokyo.
The English version of the tutorial was first released on October 23, 2001. It was based on Candidate Recommendation of XSL Specification.
Minor revised version was released on May 6th, 2002 in order to be conformant to Recommendation of XSL Specification Version 1.0.
This version, released on February, 2005, was made by adding the contents of indexes, functions for PDF creation, reference to appendix and much more substantial contents.