<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE doc SYSTEM "SampleDoc.dtd">
<doc toc="true" toclevel="1" cover="true" xmlns:fo="http://www.w3.org/1999/XSL/Format"><!--doc toc="true" cover="true" xmlns:fo="http://www.w3.org/1999/XSL/Format"--><head><date>June, 2001
</date>
<author logo="ahlogo.png" width="41.54mm" height="8.73mm" >Antenna House, Inc.<br />Copyright &#x00a9; 2001 Antenna House, Inc.</author>
<abstract>
This report explains the way to edit XSLT stylesheet that transform XML document file into XSL-FO.
</abstract>
<!--title breakpos="12"--><title>How to Develop Stylesheets  <br/>for XML to XSL-FO Transformation</title>
</head><body><section logo="XSLFormatter.bmp"><title>Preface</title><p>
XSL has been brought to the attention of a wide audience as a specification for displaying and printing the XML document. The following is general process to transform the XML document into XSL Formattiong Objects (XSL-FO) and print it.
</p><ul><li>Develop stylesheets that conforms to the DTD of source XML document to create the target output.
</li><li>
Input the  XML document and  the XSLT stylesheet to the XSLT processor to create XSL-FO.
</li><li>
 Get the target outputs such as prints, PDF outputs, by the XSL-FO processor.
</li></ul>
<figure src="sikumi-en.png">
<title>
Generating XSL-FO and Display/Print by XSL Formatter
</title>
</figure>
<p>

The knowledge about XSLT and XSL is necessary to develop XSLT stylesheets. 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 stylesheets by knowing some regular contents and patterns.
</p><p>

How is the developing environment of making stylesheets? For the present, we have no means to edit XSLT stylesheets for XSL in GUI mode.
Actually, we have to edit stylesheets manually by using an editor basically. After editing stylesheets, the target output can not be gained at one time. It often happens to debug the transformation process by XSLT processor. In this field, some tools began to appear. For further development of technology, it is quite sure that the developing environment and tools concerning XSLT and XSL-FO will be much more improved.
But so far, it is important to get experience about developing stylesheets. 
</p><p>
This report explains how to edit stylesheets which are used for transforming XML documents into XSL-FO according to the example of SampleDoc. SampleDoc is made for this report as a format to write a sample document. This is based on PureSmartDoc presented by Tomoharu Asami.
To make it a sample, the number of the elements is reduced and the usuful functions for writing and formatting documents are added. SampleDoc has almost the same grammer as HTML and the logic of the documents succeeds the functions of PureSmartDoc inherited from LaTex.

</p>
</section>
<section logo="XSLFormatter.bmp">
<title>
Step for XSL-FO Transformation 
</title>
<p>
Now, what steps are necessary to develop XSLT stylesheets?  These steps are explained briefly as below.
</p>
<table layout="fixed" ><col number="1" width="30%"/>
<col number="2" width="70%"/>
<thead><tr>
<th>Steps</th>
<th>Contents</th>
</tr></thead><tbody><tr>
<td>

Know the structure of the XML document
</td><td>

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 kind of elements, content of elements, appearing order of elements and value of attributes are quite necessary in order to develop a stylesheet.
</td></tr>
<tr><td>
Specify a printing form
</td><td>
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 size and layouts of printing paper, layouts of head and body, deciding whether or not to output index, table of contents, and so on.</td></tr>
<tr>
<td>

Apply a printing form to formatting objects
</td>
<td>
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 sample stylesheet. 
</td></tr><tr><td>

Develop a XSLT stylesheet
</td><td>
Put the instructions to the stylesheet in order to transfrom XML source documents into the target printing form. Map the XML source document to XSL formatting objects that can generate the output specification. The stylesheets have the similar aspect as the general programing languages, while it may be difficult if you do not understand the feature of the XSLT.  
<note>
Refer to the definition list template in this report.　In XSLT, Structure for control of the conditional branch can be made, but it is impossible to assign a value to a variable. The technique to realize by calling loops recursively is necessary.
</note>
</td></tr></tbody></table>
</section>
<section logo="XSLFormatter.bmp">
<title>
The Structure of SampleDoc
</title><p>

The following table shows the structure of SampleDoc treated in this report. For more detail, refer to SampleDoc.dtd
</p>
<table rowheight="2em"><col width="17.5%"/><col width="20.5%"/><col width="62%"/><thead><tr height="1em"><th> Element</th><th> Meaning</th><th> Definition</th></tr></thead><tbody><tr><td>
a group of block elements
</td><td>－</td><td>p | figure | ul | ol | dl | table | program | div</td></tr><tr><td>

a group of inline elements 
<br/></td><td>－</td><td>a | note | span | b | i | em | code | br
</td></tr>
<tr><td>doc<br/></td><td> root element </td><td>(head, body)</td></tr><tr><td>head<br/></td><td> header</td><td>(date | author | abstract | title)*</td></tr><tr><td>date, author, abstract, title<br/></td><td> header elements,<br/> date, author, abstract, title</td><td>
(#PCDATA | a group of inline elements)*
</td></tr><tr><td>body</td><td> body</td><td>
(chapter | part | section | a group of block elements | a group of inline elements)*
</td></tr><tr><td>part</td><td>part</td><td>(title, (chapter |a group of block elements | a group of inline elements)*)</td></tr><tr><td>chapter</td><td>chapter</td><td>(title, (section | a group of bock elements | a group of inline elements)*)
</td></tr>
<tr><td>section</td><td> section</td><td>(title, (subsection | a group of block elements | a group of inline elements)*)
</td></tr>
<tr><td>subsection</td><td> subsection</td><td>
(title, (subsubsection | a group of block elements | a group of inline elements)*)
</td></tr>
<tr><td>subsubsection</td><td>subsubsection</td><td>
(title, (a group of block elements | a group of inline elements)*)
</td>
</tr>
<tr><td>title</td><td> title</td><td>
(#PCDATA | a group of inline elements)*
</td></tr>
<tr><td>p<br/></td><td> paragraph</td><td>
(#PCDATA | a group of block elements | a group of inline elements)*

</td></tr><tr><td>figure<br/></td><td>figure</td><td>(title?)<br />
Specify a file by the src attribute.</td></tr>
<tr><td>ul<br/></td><td>
unordered list
 
</td><td>(li*)<br />
specify a character for label of line by the type attribute.

</td></tr><tr><td>ol<br/></td><td>
ordered list </td><td>(li*)<br />
Specify format of number in the label by the type attribute. 
</td></tr>
<tr><td>dl<br/></td><td>
definition list</td><td>(dt, dd)*<br/>
Specify whether to format the block in horizontal way or in vertical way by the type attribute.
</td></tr>
<tr><td>dt<br/></td><td>
definition term
</td><td>(#PCDATA | a group of block elements | a group of inline elements)*
</td>
</tr>
<tr><td>dd<br/></td><td>description of details
</td><td>
(#PCDATA | a group of block elements | a group of inline elements)*
</td></tr>

<tr><td>table<br/></td><td>
entire table
</td><td>(title?, col*, thead?, tfoot?, tbody)<br/>
Specify whether to make auto layout or fixed by the layout attribute. Specify the width of the entire table by the width attribute. Specify the row height of the entire table by the rowheight attribute.
</td></tr>
<tr><td>col<br/></td><td>
column format
</td><td>EMPTY<br/>

Speciry the number of the column by the number attribute, the width of the column by the width attribute.
</td></tr>
<tr><td>thead</td><td>
table header

</td><td>(tr*)</td></tr><tr><td>tfoot</td><td>
table footer
</td><td>(tr*)</td></tr><tr><td>tbody</td><td>table body
</td><td>(tr*)</td></tr><tr><td>tr</td><td>
table row</td><td>(th | td)*<br />Specify the height of the row by the height attribute.</td></tr><tr><td>th</td><td>
table header
</td><td>(#PCDATA | a group of inline elements | a group of block elements)*<br/>
Specify the number of the columns to be expanded accross,the number of the rows to be expanded vertically by the colspan and rowspan attributes. The align attribute allows horizontal alignment to be set to left, right, or center. The valign attribte allows vertical alignment to be set to top, middle, bottom or baseline.
</td></tr><tr><td>td</td><td>
table data
</td><td>(#PCDATA | a group of inline elements | a group of block elements)*<br/>

Specify the number of the columns to be expanded accross,the number of the rows to be expanded vertically by the colspan and rowspan attributes. The align attribute allows horizontal alignment to be set to left, right, or center. The valign attribte allows vertical alignment to be set to top, middle, bottom or baseline.</td></tr>
<tr><td>program</td><td>
program code
</td><td>(#PCDATA | title)*</td></tr>
<tr><td>div</td><td>general block element
</td><td>
(title, (general block element | general inline element)*)
<br />
The div element expands the type by the class attribute.
</td></tr><tr><td>a<br/></td><td>
anchor(link)
</td><td>(#PCDATA | a group of inline elements)*

<br/>Specify URL as the value of href attribute.
</td></tr><tr><td>note<br/></td><td>note
</td><td>(#PCDATA | a group of inline elements)*</td></tr><tr><td>b<br/></td><td>
bold typeface
</td><td>(#PCDATA | a group of inline elements)*</td></tr><tr><td>i<br/></td><td>
italic typeface</td><td>(#PCDATA | a group of inline elements)*

</td></tr><tr><td>em<br/></td><td>
emphasis
</td><td>(#PCDATA | a group of inline elements)*

</td></tr><tr><td>code<br/></td><td>
program code of the in-line elements
</td><td>(#PCDATA | a group of inline elements)*</td></tr><tr><td>span<br/></td><td>
 general in-line element
</td><td>(#PCDATA | a group of inline elements)*</td></tr><tr><td>br</td><td>
line break
<br/></td><td>EMPTY</td></tr>
</tbody></table>
<p>The feature of SampleDoc is as follows:
</p><ul><li>
The document structure starting from part to subsubsection is the same as that of PureSampleDoc. You can start writing from part, also start from section. It has a flexible sturucture so that it can map to various kinds of documents.
</li><li>
In SampleDoc, the number of the block element and in-line element are reduced to a minimun amount compared to PureSmartDoc. The div in the block element and the span in the in-line element are added to give various extentions.

</li><li>
The br element is added so that you can break lines inside of the lists, or the cells in the table, also inside of the paragraph without ending the paragraph.  
</li>
<li>
Output format of the list and table can be specified by the attributes.


<note>The problem is that the content and style is mixed.
</note></li></ul><p></p></section>

<section logo="XSLFormatter.bmp">
<title>Hello! World
</title><subsection><title>
A Simple Example of Transforming SampleDoc into XSL-FO
</title><p>
Now, we show the simplest sample XSLT stylesheet<note>The sample XSLT stylesheet in this document conforms to XSL Candidate Recommendation. We plan to revise this document in the near future in accordance with XSL Formatter V2.0.</note> that transforms SampleDoc to XSL-FO as follows.
</p><program><title>Source XML Document（Hello.xml)
</title>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot; ?&gt;
&lt;doc&gt;
  &lt;head&gt;
    &lt;title&gt;Sample&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;Hello World!&lt;/p&gt;
    &lt;p&gt;This is the first&lt;b&gt;SampleDoc&lt;/b&gt;&lt;/p&gt;
  &lt;/body&gt;
&lt;/doc&gt;
</program>
<program><title>
XSLT Stylesheet(Sample.xsl)
</title>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot; 
                              xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
&lt;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; indent=&quot;yes&quot; /&gt;

&lt;xsl:template match=&quot;doc&quot;&gt;
  &lt;fo:root xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot;&gt;
    &lt;fo:layout-master-set&gt;
      &lt;fo:simple-page-master page-height=&quot;297mm&quot; page-width=&quot;210mm&quot; 
          margin=&quot;5mm 25mm 5mm 25mm&quot; master-name=&quot;PageMaster&quot;&gt;
        &lt;fo:region-body   margin=&quot;20mm 0mm 20mm 0mm&quot;/&gt;
      &lt;/fo:simple-page-master&gt;
    &lt;/fo:layout-master-set&gt;
    &lt;fo:page-sequence master-name=&quot;PageMaster&quot;&gt;
      &lt;fo:flow flow-name=&quot;xsl-region-body&quot; &gt;
        &lt;fo:block&gt;
          &lt;xsl:apply-templates select=&quot;body&quot;/&gt;
        &lt;/fo:block&gt;
      &lt;/fo:flow&gt;
    &lt;/fo:page-sequence&gt;
  &lt;/fo:root&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;body&quot;&gt;
  &lt;xsl:apply-templates /&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;p&quot;&gt;
  &lt;fo:block&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;b&quot;&gt;
  &lt;fo:inline font-weight=&quot;bold&quot;&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:inline&gt;
&lt;/xsl:template&gt;

&lt;/xsl:stylesheet &gt;
</program>
<program><title>
Generated XSL-FO
</title>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot;?&gt;
&lt;fo:root xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot;&gt;
  &lt;fo:layout-master-set&gt;
    &lt;fo:simple-page-master page-height=&quot;297mm&quot; page-width=&quot;210mm&quot; 
          margin=&quot;5mm 25mm 5mm 25mm&quot; master-name=&quot;PageMaster&quot;&gt;
      &lt;fo:region-body margin=&quot;20mm 0mm 20mm 0mm&quot;/&gt;
    &lt;/fo:simple-page-master&gt;
  &lt;/fo:layout-master-set&gt;
  &lt;fo:page-sequence master-name=&quot;PageMaster&quot;&gt;
    &lt;fo:flow flow-name=&quot;xsl-region-body&quot;&gt;
      &lt;fo:block&gt;
        &lt;fo:block&gt;Hello World!&lt;/fo:block&gt;
        &lt;fo:block&gt;This is the first
          &lt;fo:inline font-weight=&quot;bold&quot;&gt;SampleDoc&lt;/fo:inline&gt;
        &lt;/fo:block&gt;
      &lt;/fo:block&gt;
    &lt;/fo:flow&gt;
  &lt;/fo:page-sequence&gt;
&lt;/fo:root&gt;
</program><p>
The above XSL-FO is formatted/displayed as follows.
<note>Our product XSL Formatter can save the output of XSLT processor to a file in the formatter option.
</note></p><p><div class="fo">
<fo:block >
<fo:block>Hello World!</fo:block>
<fo:block>This is the first <fo:inline font-weight="bold">SampleDoc</fo:inline></fo:block>
</fo:block>
</div>
</p></subsection><subsection><title	>Stylesheet Structure
</title><p>
The above Sample.xsl and XSL-FO show the following facts:
</p><ul><li>Most of the stylesheet consinsts of templates. The descendants of the root element consists of xsl:template elements. Each template (xsl:template) specifies the transformation that is to be applied to a element of the source XML document by the instruction match=&quot;xxx&quot; 


</li><li>Formatting objects and the XML source text in each template are output to result XSL-FO tree. Then, templates that match to the descendant elements are called by an instruction of xsl:apply-templates. 

</li></ul><p>
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 one after another, continues untill the processor returns to the root element and there are no more templates to be processed.
</p></subsection><subsection><title>

Block Element and Inline Element
</title><p>
Please note how the XSLT stylesheet maps block elements and inline elements in source element to formatting objects. 
</p><ul><li>
In the stylesheet, p elements are transformed into fo:block objects, b elements are transformed into fo:inline objects. The base of XSL-FO transformation is to map the elements of the source XML documents to either fo:block elements or fo:inline elements according to the layout instruction.
</li><li>
The elements that intend to break lines by the end tag normaly can be mapped to the fo:block objects. the elements of which the end tag do not intend to break lines can be mapped to the fo:inline objects. The attributes of source elements specify properties of formatting objects. In this case, the b element means emphasis and property of the inline object generated from b is specified as bold.  
</li></ul>
</subsection><subsection><title>
XSL-FO Tree Structure
</title><p>
Next, please pay attention to the XSL-FO tree structure. 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 to be set in pages.   
</p>
<figure src="hellostruct-en.emf">
<title>
Hello.xml Tree Structure
</title></figure>

<figure src="hellofo-en.emf">
<title>
XSL-FO Tree after XSLT Processing
</title></figure>
<p>
Fo:layout-master-set that defines the page layouts should precede fo:page-sequence that is an actual content of pages. XSLT processor processes the XML source document from the root element, seeking the templates (xsl:template) to be matched. Therefore, <b>fo:layout-master-set element should be an output from the template that processes the root element of the XML source document.
</b>

In this case, &lt;xsl:template match="doc"&gt; takes this processing.
</p><p>

The following node of the fo:flow is the same tree structure as the original document though the element names has changed.
<b>The nodes existed in the original document</b>are transfered  as it used to be, using &lt;xsl:template match=&quot;xxx&quot;&gt;～&lt;xsl:apply-templates;&gt; The result has the same tree structure.
In the Sample.xsl, the information described in &lt;head&gt;～&lt;/head&gt; of source XML document is not output. It is because the child element &lt;body&gt;is specified to be applied but &lt;head&gt; element is avoided according to the instruction of &lt;xsl:apply-templates select=&quot;body&quot; /&gt;

</p></subsection></section>
<section logo="XSLFormatter.bmp">
<title>

Printing Form Specification
</title>
<p>
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.
</p>
<div class="definitiontable"><title>
Page Format
</title><table rowheight="2em"><col width="30%"/><col width="70%"/><thead><tr height="1em"><th>Item


</th><th>
Specification
</th></tr></thead>
<tbody><tr><td>
Paper size
</td><td>
Letter size (8.5in x 11in)
</td></tr><tr><td>Orientation
</td><td>
Portrait
</td></tr><tr><td>
Writing mode

</td><td>
lr-tb 
</td></tr><tr><td>Margins
</td><td>
Margin Top：5mm, Bottom：5mm, Left：25mm, Right：25mm
</td></tr><tr><td>
Header, Hooter
</td><td>
Specify the header, footer regions. Do not set text inside the whitespace on the both side of the body.
</td></tr></tbody>
</table>
</div>
<div class="definitiontable"><title>
Header Region
</title><table rowheight="2em"><col width="30%"/><col width="70%"/><thead><tr height="1em"><th>
Item
</th><th>Specification
</th></tr></thead>
<tbody><tr><td>
Extent

</td><td>10mm</td></tr><tr><td>
Writing Mode
</td><td>lr-tb</td></tr><tr><td>
Content
</td><td>
Print the title 
<br/>
Font size 9pt, It is center aligned, bottom aligned in the block progression derection.
</td></tr></tbody>
</table>
</div>

<div class="definitiontable"><title>
Footer Region
</title><table rowheight="2em"><col width="30%"/><col width="70%"/><thead><tr height="1em"><th>
Item
</th><th>
Specification
</th></tr></thead>
<tbody><tr><td>
Extent
</td><td>10mm</td></tr><tr><td>
Writing Mode
</td><td>lr-tb</td></tr><tr><td>
Contents
</td><td>
Print the page numbers.  Number format -n-
<br/> Font size 9pt, It is center aligned, top aligned in the block progression direction.</td></tr></tbody>
</table>
</div>

<div class="definitiontable"><title>
Body Region
</title><table rowheight="2em"><col width="30%"/><col width="70%"/><thead><tr height="1em"><th>
Item
</th><th>
Specification
</th></tr></thead>
<tbody><tr><td>Margin
</td><td>
Margin top：20mm, bottom：20mm, left：0mm, right：0mm</td></tr><tr><td>
Content
</td><td>

Consists of head, table, list, paragraph, image.
</td></tr><tr><td>
Writing mode
</td><td>lr-tb</td></tr><tr><td>Column</td><td>1</td></tr><tr><td>Default font size
</td><td>10pt</td></tr><tr><td>Text align

</td><td>
justify
</td></tr><tr><td>
Other conditions
</td><td>
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.
</td></tr></tbody>
</table>
</div>
<!--figure src="playout.png" width="165.63mm" height="171.71mm"--><figure src="playouten.emf"><title>
The Layout of the Region-body
</title></figure><p>
The Page layout of the body region is fixed according to these instructions. The elements of the head and table should be also described in output specification. Although, we will explain these elements later individually . Beside the body part, a front cover and a content also should be specified, that have the same paper size, but defferent page layout from the body part.
</p>
</section>
<section logo="XSLFormatter.bmp">
<title>Sample2fo.xsl Stylesheet
</title><subsection><title>
What is Sample2fo.xsl?
</title><p>
Sample2fo.xsl is a sample of a XSLT stylesheet that is made by revising Sdoc2fo.xsl for this SanpleDoc.
Sdoc2fo.xsl is put on the Web by our company as a sample XSLT stylesheet for transforming PureSmartDoc into XSL-FO. Sample2fo.xsl achieves the output specification described in the last chapter, processes  book covers, contents, headers, hooters, footnotes, images and so on.
</p></subsection><subsection><title>Sample2fo.xsl Structure

</title><p>Sample2fo.xsl consists of the following top level XSLT elements.
</p>
<table rowheight="2em">
<col width="25%"/><col width="75%"/><thead><tr height="1em">
<th>
XSLT elements
</th>
<th>

Contents, Usage
</th>
</tr></thead><tbody><tr>
<td>
xsl:param</td><td>

Specify the paper size in the whole stylesheet as a parameter.
</td></tr>
<tr>
<td>
xsl:attribute-set</td><td>
Specify one or more attributes as members of an attribute set, when you may apply the same group of attributes to many different elements.
</td></tr><tr>
<td>
xsl:template match=&quot;xxx&quot;</td><td>Template for trasformation, template matchs each nodes of source XML documment. It is called by &lt;xsl:apply-templates /&gt;
</td></tr>
<tr>
<td>
xsl:template name=&quot;yyy&quot;</td><td>
This is a subroutine which is explicitly invoked by &lt;xsl:call-template name=&quot;yyy&quot;/&gt;
</td></tr>
</tbody></table>
<p>
xsl:param, xsl:attribute-set is not necessarily required, but they have the following features:
</p><ul><li>
The stylesheet can be easy to see, easy to be handled by separating their roles. Properties of formatting objects are defined by xsl:attribute-set, while the transformation are defined by xsl:template.
</li><li>
xsl:param provides a parameter at the time application calls the XSLT processor. It is possible to control a stylesheet processing externally depending upon the value of xsl:param. 
</li></ul><p type="continue"></p>
<program><title>
An example of using xsl:param
</title>
&lt;!-- Specify whether to make a table of contents or not --&gt;
&lt;xsl:param name=&quot;toc-make&quot; select=&quot;false()&quot;/&gt;
&lt;!-- Specify a paper size --&gt;
&lt;!-- Refer to $paper-width, $paper-height for the varue. --&gt;
&lt;xsl:param name="paper-width"&gt;8.5in&lt;/xsl:param&gt;
&lt;xsl:param name="paper-height"&gt;11in&lt;/xsl:param&gt;
</program><program><title>
An example of using xsl:attribute-set

</title>
&lt;!-- Specify the property of formatting object that match to the p element --&gt;
 &lt;!-- Refer to xsl:use-attribute-sets=&quot;p&quot; --&gt;
&lt;xsl:attribute-set name=&quot;p&quot;&gt;
  &lt;xsl:attribute name=&quot;text-indent&quot;&gt;1em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;0.6em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;0.6em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align&quot;&gt;justify&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;
</program><p>

From now on, we will explain the stylesheet according to this Sample2fo.xsl.
</p></subsection>
</section>
<section logo="XSLFormatter.bmp"><title>
Page Format Specification
</title>
<div class="column">
<title>
Output Specification
</title><ul><li>
There are three page formats, front cover, table of contents and body. 
</li><li>Page format for the body is defined in the print form specification.
</li><li>
The page format for the front cover and the table of contents are basically the same as that of the body. But the page numbers and the document name are not included. Therefore they have no header, footer regions.
</li></ul></div><!--
<p>
The front cover and the table of contents have a common layout as shown below.
</p><figure src="clayouten.emf">figure src="clayout.png" width="165.63mm" height="171.71mm"<title>A layout of the front cover and the table of contents
</title></figure>--><p>
The XSLT stylesheet is shown below.
</p><program><title>
Definition of page layouts in the stylesheet
</title>&lt;fo:layout-master-set&gt;
  &lt;fo:simple-page-master margin=&quot;5mm 25mm 5mm 25mm&quot; master-name=&quot;PageMaster&quot;&gt;
    &lt;xsl:attribute name=&quot;page-height&quot;&gt;
      &lt;xsl:value-of select=&quot;$paper-height&quot;/&gt;
    &lt;/xsl:attribute&gt;
    &lt;xsl:attribute name=&quot;page-width&quot;&gt;
      &lt;xsl:value-of select=&quot;$paper-width&quot;/&gt;
    &lt;/xsl:attribute&gt;
    &lt;fo:region-body   margin=&quot;20mm 00mm 20mm 00mm&quot;/&gt;
    &lt;fo:region-before  border-after-style=&quot;solid&quot; border-width=&quot;1pt&quot; extent=&quot;10mm&quot; display-align=&quot;after&quot;/&gt;
    &lt;fo:region-after  border-before-style=&quot;solid&quot; border-width=&quot;1pt&quot; extent=&quot;10mm&quot; display-align=&quot;before&quot;/&gt;
  &lt;/fo:simple-page-master&gt;

  &lt;fo:simple-page-master  margin=&quot;25mm 25mm 25mm 25mm&quot; master-name=&quot;PageMaster-Cover&quot;&gt;
    &lt;xsl:attribute name=&quot;page-height&quot;&gt;
      &lt;xsl:value-of select=&quot;$paper-height&quot;/&gt;
    &lt;/xsl:attribute&gt;
    &lt;xsl:attribute name=&quot;page-width&quot;&gt;
      &lt;xsl:value-of select=&quot;$paper-width&quot;/&gt;
    &lt;/xsl:attribute&gt;
    &lt;fo:region-body  margin=&quot;0mm 0mm 0mm 0mm&quot;/&gt;
  &lt;/fo:simple-page-master&gt;
  
  &lt;fo:simple-page-master margin=&quot;25mm 25mm 25mm 25mm&quot;  master-name=&quot;PageMaster-TOC&quot;&gt;
    &lt;xsl:attribute name=&quot;page-height&quot;&gt;
      &lt;xsl:value-of select=&quot;$paper-height&quot;/&gt;
    &lt;/xsl:attribute&gt;
    &lt;xsl:attribute name=&quot;page-width&quot;&gt;
      &lt;xsl:value-of select=&quot;$paper-width&quot;/&gt;
    &lt;/xsl:attribute&gt;
    &lt;fo:region-body  margin=&quot;0mm 0mm 0mm 0mm&quot;/&gt;
  &lt;/fo:simple-page-master&gt;
&lt;/fo:layout-master-set&gt;
</program><page /><p>
Master name properties of fo:simple-page-master are set as follows:
</p>
<table rowheight="2em">
<col width="20%"/><col width="25%"/><col width="50%"/>
<thead><tr height="1em">
<th>master-name</th>
<th>
Use
</th>
<th>The template that refers this simple-page-master</th>
</tr></thead><tbody><tr>
<td>
PageMaster-Cover</td><td>For a front cover
</td><td>&lt;xsl:template match=&quot;doc/head&quot;&gt;</td></tr>
<tr>
<td>
PageMaster-TOC</td><td>
Page format for table of contents
</td><td>&lt;xsl:template name=&quot;toc&quot;&gt;</td></tr>
<tr>
<td>
PageMaster</td><td>
Page format for body</td><td>&lt;xsl:template match=&quot;body&quot;&gt;</td></tr>
</tbody></table>

<p>
The XSL-FO tree must be arranged as follows by using this page master.

<figure src="layoutrefen.emf" ><title>Fo tree structure relating to page layout
</title></figure></p>
</section>

<section logo="XSLFormatter.bmp"><title>
Output Control of the Whole Stylesheet
</title>
<div class="column">
<title>
Requirement for processing conditions 
</title><ul><li>Fo tree is generated in order of fo:page-sequence of the front cover, fo:page-sequene of the table of contents, fo:page-sequence of body. 
</li><li>The front cover and the table of contents cannot be created by the stylesheet made in order of the XML source document, so you have to make the subroutine templates that create the front cover and the table of contents.

</li><li>
These processings are controled by the templates that process the doc element, that is the root element.
</li></ul></div>

<p>
The templates that process the doc elements created according to the requirement for processing conditions are shown below. And the order is fo:layout-master-set outputs, making a front cover, making a table of contens, processing the body text. In the process of writing documents, a front page and a table of contens are not everytime necessary. It is possible for the attributes of doc elements to control whether to make these or not.

</p><program><title>The templates that process the doc elements
</title>&lt;xsl:param name=&quot;toc-make&quot; select=&quot;false()&quot;/&gt;
&lt;xsl:param name=&quot;cover-make&quot; select=&quot;false()&quot;/&gt;

&lt;xsl:template match="doc"&gt;
  &lt;fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
    &lt;xsl:call-template name="xml-lang" /&gt;
    &lt;fo:layout-master-set&gt;
      &lt;!-- Specify the page layout(fo:simple-page-master). This part is omitted--&gt;
    &lt;/fo:layout-master-set&gt;
    &lt;!-- Make a front cover processed by the head elements. --&gt;
    &lt;xsl:if test="$cover-make or @cover!='false'"&gt;
      &lt;xsl:apply-templates select="head" /&gt;
    &lt;/xsl:if&gt;

    &lt;!-- Call the template that creates a table of contents. --&gt;
    &lt;xsl:if test="$toc-make or @toc!='false'"&gt;
      &lt;xsl:call-template name="toc" /&gt;
    &lt;/xsl:if&gt;

    &lt;!-- Process the text (descendants of the body elements) --&gt;
    &lt;xsl:apply-templates select="body" /&gt;
  &lt;/fo:root&gt;
&lt;/xsl:template&gt;

</program>
</section>


<section logo="XSLFormatter.bmp"><title>
Creating a Front Cover
</title><div class="column">
<title>
Output Specification
</title><ul><li>
Output contents of the title, the author, the date, those are children of the head element in the front page but not output the abstruct.
</li><li>
The width of the block that contains the title is 130mm, the height is 20mm, and the block must be centered, using gray for the background color, dark gray for the border color. The title is placed 25mm down from the margin top, and make a 122mm height space between the title and the author to be written next. Use the font size 24pt, font style Arial. the text must be centered inside the block.
</li><li>

The width of the block that contains the date is 160mm and the block must be centered, using no background color, no border. Use the font size 14pt, font style Times New Roman. Make a 5mm height space between the date and the author.
</li><li>
The width of the block that contains the author is 160mm and the block must be centered, using no background color, no border. Use the font size 14pt, font style Times New Roman. When a image of logotype is specified to the author, put it preceding the author.

</li></ul></div>
<p>
The front cover is created by the templates that process the head. 
</p><program><title>Format attributes of title, auther, date.

</title>&lt;!-- cover --&gt;
&lt;xsl:attribute-set name=&quot;cover.title&quot; &gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;25mm&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before.conditionality&quot;&gt;retain&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;122mm&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-size&quot;&gt;24pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;&quot;Arial&quot;&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align&quot;&gt;center&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align-last&quot;&gt;center&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;start-indent&quot;&gt;18mm&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;width&quot;&gt;130mm&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;height&quot;&gt;20mm&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;background-color&quot;&gt;#EEEEEE&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;border-style&quot;&gt;outset&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;border-color&quot;&gt;#888888&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;padding-top&quot;&gt;5pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;padding-bottom&quot;&gt;5pt&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;cover.date&quot; &gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;5mm&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-size&quot;&gt;14pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;&quot;Times New Roman&quot;&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align&quot;&gt;center&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align-last&quot;&gt;center&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;width&quot;&gt;160mm&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;cover.author&quot; &gt;
  &lt;xsl:attribute name=&quot;font-size&quot;&gt;14pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;&quot;Times New Roman&quot;&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align&quot;&gt;center&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align-last&quot;&gt;center&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;width&quot;&gt;160mm&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

</program>
<program><title>

The templates that transform the head elements
</title>&lt;xsl:template match=&quot;doc/head&quot;&gt;
  &lt;fo:page-sequence master-name=&quot;PageMaster-Cover&quot;&gt;
    &lt;fo:flow flow-name=&quot;xsl-region-body&quot; &gt;
     &lt;fo:block-container  xsl:use-attribute-sets=&quot;cover.title&quot;&gt;
       &lt;xsl:apply-templates select=&quot;/doc/head/title&quot;/&gt;
     &lt;/fo:block-container&gt;
      &lt;fo:block-container   xsl:use-attribute-sets=&quot;cover.date&quot;&gt;
        &lt;xsl:apply-templates select=&quot;/doc/head/date&quot;/&gt;
      &lt;/fo:block-container&gt;
      &lt;fo:block-container   xsl:use-attribute-sets=&quot;cover.author&quot;&gt;
        &lt;xsl:apply-templates select=&quot;/doc/head/author&quot;/&gt;
      &lt;/fo:block-container&gt;
    &lt;/fo:flow&gt;
  &lt;/fo:page-sequence&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;doc/head/title&quot;&gt;
  &lt;fo:block&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;doc/head/date&quot;&gt;
  &lt;fo:block&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;doc/head/author&quot;&gt;
  &lt;fo:block&gt;
    &lt;xsl:if test=&quot;@logo&quot; &gt;
      &lt;xsl:call-template name=&quot;author.logo.img&quot;/&gt;
    &lt;/xsl:if&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name=&quot;author.logo.img&quot;&gt;
  &lt;xsl:choose&gt;
    &lt;xsl:when test=&quot;@pos=&apos;side&apos;&quot;&gt;
      &lt;fo:inline space-end=&quot;1em&quot;&gt;
        &lt;fo:external-graphic src=&quot;{@logo}&quot;&gt;
          &lt;xsl:if test=&quot;@width and @height&quot;&gt;
            &lt;xsl:attribute name=&quot;content-width&quot; &gt;
              &lt;xsl:value-of select=&quot;@width&quot; /&gt;
            &lt;/xsl:attribute&gt;
            &lt;xsl:attribute name=&quot;content-height&quot;&gt;
              &lt;xsl:value-of select=&quot;@height&quot; /&gt;
            &lt;/xsl:attribute&gt;
          &lt;/xsl:if&gt;
        &lt;/fo:external-graphic&gt;
      &lt;/fo:inline&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;fo:block space-after=&quot;1em&quot;&gt;
        &lt;fo:external-graphic src=&quot;{@logo}&quot;&gt;
          &lt;xsl:if test=&quot;@width and @height&quot;&gt;
            &lt;xsl:attribute name=&quot;content-width&quot; &gt;
              &lt;xsl:value-of select=&quot;@width&quot; /&gt;
            &lt;/xsl:attribute&gt;
            &lt;xsl:attribute name=&quot;content-height&quot;&gt;
              &lt;xsl:value-of select=&quot;@height&quot; /&gt;
            &lt;/xsl:attribute&gt;
          &lt;/xsl:if&gt;
        &lt;/fo:external-graphic&gt;
      &lt;/fo:block&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt;
</program>

<p>
The template structure is very simple. Only apply the templates first to the title, then the date, and then the author.</p><p>
In order to layout the title, we use fo:block-container. The width and the height of fo:block-container are specified as 130mm and 20mm. The width of the text region is 215.9mm(8.5in) - 25mm - 25mm = 165.9mm.
It is much better if there is a function to center fo:block-container itself, but there is not. Subtract 130mm (the width of fo:block-container) from 165.9mm. Devide 35.9mm ( the result )into two halves and then specify the start-indend = 18mm.

</p><p>
The title block is the first block in the region-body, so it is replaced just under the margin top by optimization even if space-befor=&quot;25mm&quot; is specified. You can make a space forcibly by specifying
space-before.conditionality=&quot;retain&quot;.
</p><p>
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. See the title of this report for an example. 
</p></section>


<section logo="XSLFormatter.bmp"><title>
Creating a Table of Contents

</title><div class="column">
<title>
Output Specification
</title><ul><li> The title of parts, chapters, sections, and subsections in the source XML document are output for a table of contents. 

</li><li>Table of contents is positioned next to the front cover by feeding a page. The title is "Table of Contents". The background color is gray.
</li><li>

The contents of each line consist of the each title in the part, chapter, section, subsection, and leaders (rows of dots), a page number.


</li><li>

Space before, left indent, font size, font weight are specified in each line according to the nest level of each part, chapter, section, subsection.
</li></ul></div>
<subsection><title>

Templates for Creating Contents

</title><p>
The 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 &lt;xsl:call-template name=&quot;toc&quot;&gt;
</p><program><title>
Toc template
</title>&lt;xsl:template name=&quot;toc&quot;&gt;
  &lt;!-- generate fo:page-sequence--&gt;
    &lt;fo:page-sequence master-name=&quot;PageMaster-TOC&quot;&gt;
    &lt;!-- generate flow applied to region-body --&gt;
    &lt;fo:flow flow-name=&quot;xsl-region-body&quot; &gt;
      &lt;!--generate a block of table of contents--&gt;
      &lt;fo:block xsl:use-attribute-sets=&quot;div.toc&quot;&gt;
        &lt;!--generate the title「Table of Contents」--&gt;
        &lt;fo:block xsl:use-attribute-sets=&quot;h2&quot;&gt;Table of Contents&lt;/fo:block&gt;
        &lt;!-- select the elements of part, chapter, section, subsection,
                 subsubsection from the whole XML documents--&gt;
        &lt;xsl:for-each select=&quot;//part |
                              //chapter |
                              //section |
                              //subsection |
                              //subsubsection&quot;&gt;
          &lt;!-- apply template for each element to generate each line of the contents.--&gt;
          &lt;xsl:call-template name=&quot;toc.line&quot;/&gt;
        &lt;/xsl:for-each&gt;
      &lt;/fo:block&gt;
    &lt;/fo:flow&gt;
  &lt;/fo:page-sequence&gt;
&lt;/xsl:template&gt;
</program>
<p>

The toc template processes in the following order.
</p>
<ol><li>
Create a new page-sequence. This page-sequence refer to fo:simple-page-master described in master-name=&quot;PageMaster-TOC&quot; for a new page layout. Because the new page-sequence is created, the page is broken when it is printed.
</li><li>
Next, generate fo:flow object in the region-body. Create a block that contains a whole table of contents by applying attribute-set that is a name of div.toc. This attribte-set specifies the background color gray. Then, create a title "Table of Contents".
</li><li>
xsl:for-each select=&quot;...&quot; is used to create a set of nodes consisting of the parts, characters, sections, subsections, subsubsection of whole document. Then, each node is sent to toc.line template that processes a line of the contents. In this processing, xsl:sort is not specified, the nodes in the set are created in appearing order.
</li></ol>
<p>
This template is called from the template that processes the doc elements. So, &quot;current node&quot; is doc element node. xsl:for-each change this current node into each node group specified by the select attribute. Therefore, current node is one of the five elements, part, chapter, section, subsection, and subsubsection in the toc.line template. When xsl:for-each finished processing, the current node returns to the previous doc element node.
</p></subsection>
<subsection><title>Templates that Create Lines of TOC
</title><p>

The toc.line template creates a line of contents. 
</p><program><title>
The toc.line template creates each line of contents.
</title>
&lt;!-- global parameter and variable used when creating the table of contents. --&gt;
&lt;xsl:param name=&quot;toc-level-default&quot; select=&quot;3&quot;/&gt;
&lt;!-- The template that creates the table of contents --&gt;
&lt;xsl:variable name=&quot;toc-level-max&quot;&gt;
  &lt;xsl:choose&gt;
    &lt;xsl:when test=&quot;not (doc/@toclevel)&quot;&gt;
      &lt;xsl:value-of select=&quot;$toc-level-default&quot;/&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;xsl:value-of select=&quot;number(doc/@toclevel)&quot;/&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:variable&gt;

&lt;xsl:template name=&quot;toc.line&quot;&gt;
  &lt;!-- Count the nest level of current node,
    set the value to &quot;level&quot; local variable. --&gt;
  &lt;xsl:variable name=&quot;level&quot; select=&quot;count(ancestor-or-self::part | 
                                          ancestor-or-self::chapter |
                                          ancestor-or-self::section |
                                          ancestor-or-self::subsection |
                                          ancestor-or-self::subsubsection )&quot; /&gt;
 &lt;!-- Test if the nest level can be a target. --&gt;
  &lt;xsl:if test=&quot;$level &amp;lt;= $toc-level-max&quot;&gt;
    &lt;!-- Create fo:block for each line of toc． --&gt;
    &lt;fo:block  text-align-last=&quot;justify&quot;&gt;
      &lt;!-- Widen the margin left in proportion to a nest level.--&gt;
      &lt;xsl:attribute name=&quot;margin-left&quot;&gt;
        &lt;xsl:value-of select=&quot;$level - 1&quot;/&gt;
        &lt;xsl:text&gt;em&lt;/xsl:text&gt;
      &lt;/xsl:attribute&gt;
      
      &lt;!-- space-before becomes larger in proportion 
           that the nest level becomes upper.--&gt;
      &lt;xsl:attribute name=&quot;space-before&quot;&gt;
          &lt;xsl:choose&gt;
          &lt;xsl:when test=&quot;$level=1&quot;&gt;5pt&lt;/xsl:when&gt;
          &lt;xsl:when test=&quot;$level=2&quot;&gt;3pt&lt;/xsl:when&gt;
          &lt;xsl:when test=&quot;$level=3&quot;&gt;1pt&lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;1pt&lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
      &lt;/xsl:attribute&gt;
      &lt;!-- font-size is processed in the same way--&gt;
      &lt;xsl:attribute name=&quot;font-size&quot;&gt;
        &lt;xsl:choose&gt;
          &lt;xsl:when test=&quot;$level=1&quot;&gt;1em&lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;0.9em&lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
      &lt;/xsl:attribute&gt;
      &lt;!-- font-weight is also processed in the same way --&gt;
      &lt;xsl:attribute name=&quot;font-weight&quot;&gt;
        &lt;xsl:value-of select=&quot;800 - $level * 100&quot;/&gt;
      &lt;/xsl:attribute&gt;
      &lt;!-- Below is the data of the table of contents --&gt;
      &lt;xsl:value-of select=&quot;title&quot; /&gt;
      &lt;fo:leader leader-pattern=&quot;dots&quot;/&gt;
     &lt;!-- Output fo:page-number-citation. When the page is printed, 
          it is replaced by the page number.--&gt;
      &lt;fo:page-number-citation ref-id=&quot;{generate-id()}&quot;/&gt;
    &lt;/fo:block&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;
</program>

<p>
The toc.line template processes in the following order.</p>
<ol><li>Count the depth of the nest of the current node (nest level) from the root node . Set the value to a level variable.
</li><li> If a nest level is on or below the level of "toc-level-max", it is processed. If not, it is not processed. The level of "toc-level-max" is specified by the toclevel attribute of the doc element. If the level is not specified, the varue is 3.
</li><li>
Create fo:block for each line in the table of the contents.
</li><li>According to the depth from the root node, determine the the property value of indent, font size, font weight.

</li><li>
 Output contents of title elements, leaders, page numbers.
</li></ol>
<page />
<subsubsection><title>
Count the Nest Level
</title>
<p>
The nest level can be counted by setting the local variable called level 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 or the ancestor nodes. This chart is shown below:
</p>
<figure src="levelcal-en.emf"><title>
Count the nest level from the root element
</title></figure>
</subsubsection>

<subsubsection><title>
Set properties according to the nest level.
</title>
<p>
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. 
</p>

<table><thead><tr><th rowspan="2" align="center" valign="center">
Properiy
</th><th colspan="5" align="center">
Nest level
</th>
</tr>
<tr><th align="center">1</th><th align="center">2</th>
<th align="center">3</th>
<th align="center">4</th>
<th align="center">5</th>
</tr>
</thead><tbody><tr><td>margin-left</td>
<td>0em</td>
<td>1em</td>
<td>2em</td>
<td>3em</td>
<td>4em</td>
</tr><tr><td>space-before</td>
<td>5pt</td>
<td>3pt</td>
<td>1pt</td>
<td>1pt</td>
<td>1pt</td>
</tr><tr><td>font-size</td>
<td>1em</td>
<td>0.9em</td>
<td>0.9em</td>
<td>0.9em</td>
<td>0.9em</td>
</tr><tr><td>font-weight</td>
<td>700</td>
<td>600</td>
<td>500</td>
<td>400</td>
<td>300</td>
</tr></tbody></table>
</subsubsection>

<subsubsection><title>
Create page numbers
</title>
<p>You have to create page numbers that show the page where each part,chapter, section, subsection appear. <em>Page numbers cannot be fixed until the formatter pagenates the XSL-FO instance.</em>
</p><p>For the purpose, XSL provides the function fo:page-number-citation. The formatter replaces fo:page-number-citation with the page number in the end of the processing. The ref-id property specifies which page number is replaced. The formatter finds formatting object that has the same value in the id property as that specified by ref-id. Then, the page number that the formatting object belongs to are given. Therefore fo:block generated from the part, chapter, section, subsection elements must have id properties. This mechanism is shown below.
</p><figure src="pciteen.emf" ><title>
Mechanism of fo:page-number-citation
</title></figure>
<p> In the template, the generate-id() function is used as the value of the ref-id property. XSLT processor generates the unique characters using generate-id() to distinguish current node. </p>

</subsubsection>

<subsubsection>
<title>fo:leader</title>
<p>

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=&quot;dots&quot; is specified. It plays the role to fill the space between the title and the page number. It is important that text-align-last=&quot;justify&quot; in fo:block specifies to justify the entire line. So, the titles are left-justified and the page numbers are right-justified, then the leader pattern fill the space between them.
</p>
<p>
fo: leader property can specify various patterns as shown below. fo:leader properties are written in the left side.
</p>
<div class="fo">
<fo:block text-align-last="justify" margin-left="1em" space-before="3pt" font-size="0.9em" >leader-pattern=&quot;dots&quot;<fo:leader leader-pattern="dots"/>
99
</fo:block>
<fo:block text-align-last="justify" margin-left="1em" space-before="3pt" font-size="0.9em" >leader-pattern=&quot;use-content&quot; (content=&quot;*&quot;)<fo:leader leader-pattern="use-content">*</fo:leader>
99
</fo:block>
<fo:block text-align-last="justify" margin-left="1em" space-before="3pt" font-size="0.9em" >leader-pattern=&quot;rule&quot; rule-style=&quot;dotted&quot;<fo:leader leader-pattern="rule" rule-style="dotted"/>
99
</fo:block>
<fo:block text-align-last="justify" margin-left="1em" space-before="3pt" font-size="0.9em" >leader-pattern=&quot;rule&quot; rule-style=&quot;dashed&quot;<fo:leader leader-pattern="rule" rule-style="dashed"/>
99
</fo:block>
<fo:block text-align-last="justify" margin-left="1em" space-before="3pt" font-size="0.9em" >leader-pattern=&quot;rule&quot; rule-style=&quot;solid&quot;<fo:leader leader-pattern="rule" rule-style="solid"/>
99
</fo:block>
<fo:block text-align-last="justify" margin-left="1em" space-before="3pt" font-size="0.9em" >leader-pattern=&quot;rule&quot; rule-style=&quot;double&quot;<fo:leader leader-pattern="rule" rule-style="double"/>
99
</fo:block>
<fo:block text-align-last="justify" margin-left="1em" space-before="3pt" font-size="0.9em" >leader-pattern=&quot;rule&quot; rule-style=&quot;groove&quot;<fo:leader leader-pattern="rule" rule-style="groove"/>
99
</fo:block>
<fo:block text-align-last="justify" margin-left="1em" space-before="3pt" font-size="0.9em" >leader-pattern="rule" rule-style="ridge"<fo:leader leader-pattern="rule" rule-style="ridge"/>
99
</fo:block>

</div>
</subsubsection>
<subsubsection>
<title>Example of the generated contents
</title>
<p>
Shown below is an example of toc created taking the steps described.
</p>
<program><title>
Generated table of contents
</title>
&lt;fo:block text-align-last=&quot;justify&quot; margin-left=&quot;0em&quot; space-before=&quot;5pt&quot; font-size=&quot;1em&quot; font-weight=&quot;700&quot;&gt;
  Preface 
  &lt;fo:leader leader-pattern=&quot;dots&quot;/&gt;
  &lt;fo:page-number-citation ref-id=&quot;IDA4AIOB&quot;/&gt;
&lt;/fo:block&gt;
</program>
<p>
See the table of contents in this report for an output example.
</p>
</subsubsection>

</subsection>
</section>

<section logo="XSLFormatter.bmp">
<title>
Processing the Body
</title>
<div class="column">
<title>
Output specification
</title>
<ul>
<li>
Process all the descendants or self of the body elements in the source XML document.
</li>
<li>
The page layout of the body is as described in the Printing Form Specification.
</li>
</ul></div>
<subsection>
<title>
The Template Processing the Body
</title>
<p>The body in the XML source document is contained to the decendants or self of the body element. Shown below are the templates that process the body element. 
</p>

<program><title>The template processing the body element
</title>&lt;xsl:template match=&quot;body&quot;&gt;
  &lt;!-- Create a new fo:page-sequence --&gt;
  &lt;fo:page-sequence master-name=&quot;PageMaster&quot;&gt;    
    &lt;!-- Place the document title in the header region. --&gt;
    &lt;fo:static-content flow-name=&quot;xsl-region-before&quot;&gt;
      &lt;fo:block text-align=&quot;center&quot; font-size=&quot;9pt&quot;&gt;
        &lt;xsl:if test=&quot;/doc/head/title&quot;&gt;
          &lt;xsl:value-of select=&quot;/doc/head/title&quot;/&gt;
        &lt;/xsl:if&gt;
      &lt;/fo:block&gt;
    &lt;/fo:static-content&gt;
    
    &lt;!-- Place the page numbers in the footer region. --&gt;
    &lt;fo:static-content flow-name=&quot;xsl-region-after&quot;&gt;
      &lt;fo:block text-align=&quot;center&quot; font-size=&quot;9pt&quot;&gt;
    - &lt;fo:page-number/&gt; -
      &lt;/fo:block&gt;
    &lt;/fo:static-content&gt;
    
    &lt;!-- Place a borderline between body and footnote. --&gt; 
    &lt;fo:static-content flow-name=&quot;xsl-footnote-separator&quot;&gt;
      &lt;fo:block&gt;
        &lt;fo:leader leader-pattern=&quot;rule&quot; rule-thickness=&quot;0.5pt&quot; leader-length=&quot;33%&quot;/&gt;
      &lt;/fo:block&gt;
    &lt;/fo:static-content&gt;
    
    &lt;!-- Create the flow objects of the body region. --&gt;
    &lt;fo:flow flow-name=&quot;xsl-region-body&quot; &gt;
      &lt;fo:block&gt;        
        &lt;!-- Process the descendants or self of the body element. --&gt;
        &lt;xsl:apply-templates /&gt;
      &lt;/fo:block&gt;
    &lt;/fo:flow&gt;
  &lt;/fo:page-sequence&gt;
&lt;/xsl:template&gt;
</program>
<p>
This template pocesses as shown below.
</p>
<ol>
<li>Generate a fo:page-sequence based on the new &quot;PageMaster&quot;, the page format is changed right after the table of contents.
</li>
<li>Set the header/footer regions based on the page format. Place the title of the document in the header, page numbers in the footer.
</li>
<li>Create a border region between the body and the footnote by using leaders.
</li>
<li>
Create flow objects in the body region.
</li>
<li>
xsl:apply-templates processes the descendants or self of the body element.
</li>
</ol>
<p type="continue">In order to print the page numbers, use fo:page-number object. fo:page-number creates the special inline area, the formatter replaces fo:page-number by the page number in the formatting process.
</p><p>
Use fo:leader object to create a borderline between the body and the footnote. Use solid line. The width of the line is one - third of the body region. 
</p>
</subsection>
</section>

<section logo="XSLFormatter.bmp">
<title>
Creating  Heads
</title>
<div class="column">
<title>
Output specification
</title>
<ul>
<li>
Generate heads from the title of parts, chapters, sections, subsections and subsubsections.
</li>
<li>The style of the head is not mapped for each element of part, chapter, section, subsection and subsubsection but it is mapped according to the nest level. 
</li>
<li>
The head of the top level breaks page before the block.

</li>
<li>Make it possible to set an image in the head.
</li>
</ul></div>
<subsection>
<title>
Style Conditions of the Head
</title>
<p>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. 
</p>

<table>
<col width="15%"/>
<col width="15%"/>
<col width="70%"/>
<thead>
<tr>
<th align="center">
Nest level
</th>
<th align="center">attribute-set</th>
<th align="center">
Style conditions
</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center" valign="center">1</td>
<td align="center" valign="center">h1</td>
<td>
font: size 24pt, Arial, Bold
<br/>space-after : 14pt, keep-with-next.within-page : always
<br/> 
botom border : solid 2pt, break condition : break-before=&quot;page&quot;
</td>
</tr>
<tr>
<td align="center" valign="center">2</td>
<td align="center" valign="center">h2</td>
<td>
Font : size 16pt, Arial, bold
<br/> 
space-before : 19pt, space-after : 5pt, keep-with-next. within-page : always 
</td>
</tr>

<tr>
<td align="center" valign="center">3</td>
<td align="center" valign="center">h3</td>
<td>font : size 13pt, Arial, bold
<br/>
space-before : 14pt, space-after : 5pt, keep-with-next. within-page : always 
</td>
</tr>


<tr>
<td align="center" valign="center">4</td>
<td align="center" valign="center">h4</td>
<td>
font : size 12pt, Arial, bold<br/> 
space-before : 5pt, space-after: 5pt, keep-with-next. within-page : always
</td>
</tr>

<tr>
<td align="center" valign="center">5</td>
<td align="center" valign="center">h5</td>
<td>
font : size 10pt, Arial, bold <br/> 
space-before : 3pt, space-after : 3pt, keep-with-next. within-page : always</td>
</tr>
</tbody>
</table>

<p>
These conditions of style are defined in the following stylesheet.</p>
<program><title>Style definition of the heads </title>&lt;!-- titles --&gt;
&lt;xsl:attribute-set name=&quot;h1&quot; &gt;
  &lt;xsl:attribute name=&quot;font-size&quot;&gt;24pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;&quot;Arial&quot;&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-weight&quot;&gt;bold&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;14pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;break-before&quot;&gt;page&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;keep-with-next.within-page&quot;&gt;always&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;border-after-style&quot;&gt;solid&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;border-after-width&quot;&gt;2pt&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;h2&quot; &gt;
  &lt;xsl:attribute name=&quot;font-size&quot;&gt;16pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;&quot;Arial&quot;&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-weight&quot;&gt;bold&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;19pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;5pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;keep-with-next.within-page&quot;&gt;always&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;h3&quot; &gt;
  &lt;xsl:attribute name=&quot;font-size&quot;&gt;13pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;&quot;Arial&quot;&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-weight&quot;&gt;bold&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;14pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;5pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;keep-with-next.within-page&quot;&gt;always&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;h4&quot; &gt;
  &lt;xsl:attribute name=&quot;font-size&quot;&gt;12pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;&quot;Arial&quot;&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-weight&quot;&gt;bold&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;5pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;5pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;keep-with-next.within-page&quot;&gt;always&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;h5&quot; &gt;
  &lt;xsl:attribute name=&quot;font-size&quot;&gt;10pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;&quot;Arial&quot;&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-weight&quot;&gt;bold&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;3pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;3pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;keep-with-next.within-page&quot;&gt;always&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;
</program>

<p>keep-with-next.within-page=&quot;always&quot; is specified to heads in order to avoid breaking pages before the next block. It is not specified in h1, instead, break-before=&quot;page&quot; is specified, so the page break is inserted before h1 block, a block is kept at the top of the following page and is kept with the next one. 
</p>
</subsection>

<subsection>
<title>
Head Processing Templates
</title>
<p>The templates that process the heads.  Heads are processed in one template intensively because the styles are selected according to the nest level. 
</p>
<program><title>The templates that process heads
</title>&lt;xsl:template match=&quot;part |
                     chapter |
                     section |
                     subsection |
                     subsubsection&quot;&gt;
  &lt;xsl:call-template name=&quot;title.out&quot;/&gt;
  &lt;xsl:apply-templates /&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;part/title |
                     chapter/title |
                     section/title |
                     subsection/title |
                     subsubsection/title&quot;&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name=&quot;title.out&quot;&gt;
  &lt;xsl:variable name=&quot;level&quot; select=&quot;count(ancestor-or-self::part | 
                                          ancestor-or-self::chapter |
                                          ancestor-or-self::section |
                                          ancestor-or-self::subsection |
                                          ancestor-or-self::subsubsection )&quot; /&gt;
  &lt;xsl:choose&gt;
    &lt;xsl:when test=&quot;$level=1&quot;&gt;
      &lt;fo:block xsl:use-attribute-sets=&quot;h1&quot; id=&quot;{generate-id()}&quot;&gt;
        &lt;xsl:call-template name=&quot;title.out.sub&quot;/&gt;
        &lt;xsl:value-of select=&quot;title&quot;/&gt;
      &lt;/fo:block&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test=&quot;$level=2&quot;&gt;
      &lt;fo:block xsl:use-attribute-sets=&quot;h2&quot; id=&quot;{generate-id()}&quot;&gt;
        &lt;xsl:call-template name=&quot;title.out.sub&quot;/&gt;
        &lt;xsl:value-of select=&quot;title&quot;/&gt;
      &lt;/fo:block&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test=&quot;$level=3&quot;&gt;
      &lt;fo:block xsl:use-attribute-sets=&quot;h3&quot; id=&quot;{generate-id()}&quot;&gt;
        &lt;xsl:call-template name=&quot;title.out.sub&quot;/&gt;
        &lt;xsl:value-of select=&quot;title&quot;/&gt;
      &lt;/fo:block&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test=&quot;$level=4&quot;&gt;
      &lt;fo:block xsl:use-attribute-sets=&quot;h4&quot; id=&quot;{generate-id()}&quot;&gt;
        &lt;xsl:call-template name=&quot;title.out.sub&quot;/&gt;
        &lt;xsl:value-of select=&quot;title&quot;/&gt;
      &lt;/fo:block&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test=&quot;$level=5&quot;&gt;
      &lt;fo:block xsl:use-attribute-sets=&quot;h5&quot; id=&quot;{generate-id()}&quot;&gt;
        &lt;xsl:call-template name=&quot;title.out.sub&quot;/&gt;
        &lt;xsl:value-of select=&quot;title&quot;/&gt;
      &lt;/fo:block&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;fo:block xsl:use-attribute-sets=&quot;h5&quot; id=&quot;{generate-id()}&quot;&gt;
        &lt;xsl:call-template name=&quot;title.out.sub&quot;/&gt;
        &lt;xsl:value-of select=&quot;title&quot;/&gt;
      &lt;/fo:block&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name=&quot;title.out.sub&quot;&gt;
  &lt;xsl:if test=&quot;@logo&quot;&gt;
    &lt;fo:inline space-end=&quot;5pt&quot;&gt;
      &lt;fo:external-graphic src=&quot;{@logo}&quot;&gt;
        &lt;xsl:if test=&quot;@width and @height&quot;&gt;
          &lt;xsl:attribute name=&quot;content-width&quot; &gt;
            &lt;xsl:value-of select=&quot;@width&quot; /&gt;
          &lt;/xsl:attribute&gt;
          &lt;xsl:attribute name=&quot;content-height&quot;&gt;
            &lt;xsl:value-of select=&quot;@height&quot; /&gt;
          &lt;/xsl:attribute&gt;
        &lt;/xsl:if&gt;
      &lt;/fo:external-graphic&gt;
    &lt;/fo:inline&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;
</program>

<p>The stylesheet processing heads consists of four templates. Actual title of the head is created form the title.out template. The title.out template processes in the following order:
</p>
<ol>
<li>Count the nest level of the element under processing and store the value to a level local variable.
</li>
<li>
Select style of the title from h1 to h5 according to the variable, apply it to fo:block of the title.
</li>
<li>
In the same way, create id property by generate-id() function and apply it to fo:block.
<note>．
Refer to the fo:page-number-citation of the line of the contents
</note></li>
<li>
Call the title.out.sub template that processes images.
</li>
<li>
Output the text to the title as specified.
</li>
</ol>
<p type="continue">
The second template that processes part/title - subsubsection/title become empty (nothing output). It is because the template has already processed by the title.out template and not to output the text of title when the first xsl:apply-templates invoke it again.

</p>
<subsubsection>
<title>
A generated example of the titles 
</title>
<p>
This is a geneated example of title by taking previous steps. Note that the result of generate-id() funcion is stored as the value of id.
</p>
<program><title>
Created titles
</title>&lt;fo:block font-size=&quot;24pt&quot; 
          font-family=&quot;&amp;quot;Arial&amp;quot;&quot; 
          font-weight=&quot;bold&quot; 
          space-after=&quot;14pt&quot; 
          break-before=&quot;page&quot; 
          keep-with-next.within-page=&quot;always&quot; 
          border-after-style=&quot;solid&quot; 
          border-after-width=&quot;2pt&quot; 
          id=&quot;IDA4AIOB&quot;&gt;
  &lt;fo:inline space-end=&quot;5pt&quot;&gt;
    &lt;fo:external-graphic src=&quot;XSLFormatter.bmp&quot;/&gt;
  &lt;/fo:inline&gt;
  Preface
&lt;/fo:block&gt;
</program>
</subsubsection>
</subsection>
</section>

<section logo="XSLFormatter.bmp"><title>
Processing Inline Elements
</title>

<div class="column">
<title>

Output specification
</title>
<ul>
<li>
b(bold), i(italic), em(emphasis), code(inline program code) are transformed into character properties.

</li>
<li>
The a(anchor) element only output the referenced text first, output the contents of a target end of a hypertext link of the href attribute. </li>
<li>
A note(note) is transformed into a footnote. A footnote citation is usually (n). A sequence of numbers is applied to (n).


</li>
<li>
The br(break) element breaks lines.
</li>
<li>
The span element (general inline element) only creates fo:inline.
</li>
</ul></div>

<subsection><title>
The Templates that Process b, i, em, code Elements.
</title><p>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=&quot;bold&quot;, italic is font-style=&quot;italic&quot;, em also maps to bold. The way is different from the b but it becomes the same result. Code sets monospace to font-family porperty.  </p>
<program><title>The templates that process b, i, em, code
</title>&lt;xsl:template match=&quot;b&quot;&gt;
  &lt;fo:inline font-weight=&quot;bold&quot;&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:inline&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;i&quot;&gt;
  &lt;fo:inline font-style=&quot;italic&quot;&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:inline&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;em&quot;&gt;
  &lt;fo:inline xsl:use-attribute-sets=&quot;em&quot;&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:inline&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;code&quot;&gt;
  &lt;fo:inline font-family=&quot;monospace&quot;&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:inline&gt;
&lt;/xsl:template&gt;
</program>
<p>
As fo:inline is applied, the line is not considered to break at the last of text. The example is shown below. 
</p>

<div class="column">
<p>
The inline element i (italic) becomes [
<i>Italic</i>].</p><p>The inline element (bold) becomes [
<b>
Bold typeface
</b>].</p><p>
The inline element em (emphasis) also becomes [
<b>
Bold typeface
</b>].</p>
<p>
The inline element code (inline program code) becomes [
<code>
Monospace font (apply monospace font)
</code>].</p>

</div>


</subsection>

<subsection><title>
The Anchor Element (a) 
</title><p>The anchor element (a) contains a Hypertext Reference attribute (href) which contains a URL. It is a problem how to treat a URL. In this case put a URL in parentheses, output it after the text specified by the anchor element. But if the both contents are the same, the URL is not output.
</p>
<program><title>The templates that process the (a) element
</title>&lt;xsl:template match=&quot;a&quot;&gt;
  &lt;xsl:variable name=&quot;anchor-texts&quot;&gt;
    &lt;xsl:value-of select=&quot;.&quot; /&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:apply-templates /&gt;
  &lt;xsl:if test=&quot;@href!=$anchor-texts&quot;&gt;
    &lt;fo:inline &gt;
      &lt;xsl:text&gt;(&lt;/xsl:text&gt;
      &lt;xsl:value-of select=&quot;@href&quot; /&gt;
      &lt;xsl:text&gt;)&lt;/xsl:text&gt;
    &lt;/fo:inline&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;
</program>
<p>
The example using this stylesheet is as follows:
</p>
<div class="column">
<p>&apos;This example is shown on the Web&lt;a href=&quot;http://www.w3.org/&quot;&gt; at the site of W3C&lt;/a&gt;&apos;.
<br/>
 is shown as:<br />
<code class="fo">&apos;This example is shown on the Web at the site of W3C<fo:inline>(http://www.w3.org/)</fo:inline></code>.&apos;</p>
<p>
&apos;This example is shown on the Web site at &lt;a href=&quot;http://www.w3.org/&quot;&gt;http://www.w3.org/&lt;/a&gt;.&apos; <br />is shown as:
<br/><code class="fo">
&apos;This example is shown on the Web site at http://www.w3.org/.
</code>&apos;</p>
<p>&apos;This example is shown on the Web site at &lt;a href=&quot;http://www.w3.org/&quot;&gt;http://&lt;em&gt;&lt;i&gt;www&lt;/i&gt;.&lt;i&gt;w3&lt;/i&gt;.&lt;i&gt;org&lt;/i&gt;&lt;/em&gt;/&lt;/a&gt;.&apos;<br /> is shown as:
<br/><code class="fo">&apos;This example is shown on the Web site at http://
<fo:inline font-weight="bold">
<fo:inline font-style="italic">www</fo:inline>.<fo:inline font-style="italic">w3</fo:inline>.<fo:inline font-style="italic">org</fo:inline>
</fo:inline>/</code>.&apos;</p>
</div>

</subsection>

<subsection><title>
The note Element
</title><p>The note element is transformed into XSL fo:footnote formatting object.
</p>
<program><title>The template that processes note element
</title>&lt;xsl:template match=&quot;note&quot;&gt;
  &lt;fo:footnote&gt;
    &lt;fo:inline baseline-shift=&quot;super&quot; font-size=&quot;75%&quot;&gt;
      &lt;xsl:number level=&quot;any&quot; count=&quot;//note&quot; format=&quot;(1)&quot; /&gt;
    &lt;/fo:inline&gt;
    &lt;fo:footnote-body&gt;
      &lt;fo:block xsl:use-attribute-sets=&quot;note&quot;&gt;
        &lt;fo:inline baseline-shift=&quot;super&quot; font-size=&quot;75%&quot;&gt;
          &lt;xsl:number level=&quot;any&quot; count=&quot;//note&quot;  format=&quot;(1)&quot;/&gt;
        &lt;/fo:inline&gt;
          &lt;xsl:apply-templates /&gt;
      &lt;/fo:block&gt;
    &lt;/fo:footnote-body&gt;
  &lt;/fo:footnote&gt;
&lt;/xsl:template&gt;
</program>
<p>fo:footnote object in the XSL express a footnote and the content model is (fo:inline, fo:footnote-body). The first child fo:inline expresses a footnote citation placed in the text. The next fo:footnote-body is the footnote text and it consists of the block objects like fo:block. Shown below is a typical fo:footnote object. 
</p><figure src="footnote-en.emf"><title>The typical example of a note element and a fo:footnote</title></figure><p>Generaly, the same content 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 the stylesheet processing.
</p><ol><li>

Output fo:footnote.
</li><li>

Generate fo:inline that includes a footnote citation by using xsl:number.</li><li>
A content of note element with the same footnote citation is put into a fo:block element, that is a child of the fo:footnote-body.  
</li></ol><p>
xsl:number is a XSLT processing instruction.
<code font="sans-serif">&lt;xsl:number level=&quot;any&quot; count=&quot;//note&quot; format=&quot;(1)&quot; /&gt;</code>searchs all the descendant of the note elements under the root element in appearing order, find out the same elemet as the current note element. Formats the appearing number as described in &quot;(1)&quot;,

</p><p>baseline-shift=&quot;super&quot; shifts the baseline to the default position for superscripts. Below shows the example of footnote.
</p>
<div class="column"><p><code font="sans-serif">
&quot;This is an example of footnote. Place a footnote here. &lt;note&gt; This is a footnote text. It is placed below the page and seperated from the text part.&lt;/note&gt;&quot;
</code>
is expressed as:
<br/><code font="sans-serif">
"This is an example of footnote. Place a footnote here.
<note>This is a footnote text. It is placed below the page and seperated from the text part.
</note>"</code></p></div></subsection>

<subsection><title>
The br Element
</title><p>The br element is an empty element, so it is replaced by a empty fo:block element. Then the line bleaks.

</p>
<program><title>The template that processes the br elements
</title>&lt;xsl:template match=&quot;br&quot;&gt;
  &lt;fo:block&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;
</program>

<p>The following table shows the example of the process

</p>
<div class="column"><p>&quot;In the paragraph, put &lt;b&gt; forcibly &lt;br/&gt; break a line &lt;/b&gt; because the paragraph is not finished, the attribute set before the line break can be used.&quot;
<br/>is expressed as:</p><p>&quot;In the paragraph, put<b>
forcibly
<br/>
break a line
</b>
because the paragraph is not finished, the attribute set before the line break can be used.&quot;
</p></div>
</subsection>
<subsection><title>
The span Element
</title><p>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

</p>
<program><title>The template that processes the span element</title>&lt;xsl:template match=&quot;span&quot;&gt;
  &lt;fo:inline &gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:inline&gt;
&lt;/xsl:template&gt;
</program>
</subsection>
</section>


<section logo="XSLFormatter.bmp"><title>
Processing Block Elements
</title><p>
The processsing of the block elements except tables and lists (ol,ul,dl) are explained in this chapter.  

</p>
<div class="column">
<title>Output specification
</title>
<ul>
<li>Transform p(paragraph) into a block element. 
Indent one character in the first line of the paragraph. Text align justify. Text align left at the last line. Spaces which size is font size x 0.6 are given before and after the paragraph. A paragraph is kept within a page.
</li>
<li>Figures are placed by feeding a line at the appearing point, by centering. Apply the size of the figure if the size is specified. If there is a title, place it after the figure. 
</li>
<li>Transform program element that contains program codes into fo:block formatting object. Apply monospace, use line feed, space as they are preformatted. The background color is gray. Output the title in front of the program code.

</li>
<li>
Transform div(general block element) into fo:block.

</li>
</ul></div>
<subsection><title>The p Element
</title><p>
The p element (paragraph) is frequently used. The following shows the template processing the p element.
</p>
<program>
<title>The template processing the p element
</title>
&lt;xsl:attribute-set name=&quot;p&quot;&gt;
  &lt;xsl:attribute name=&quot;text-indent&quot;&gt;1em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;0.6em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;0.6em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align&quot;&gt;justify&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;keep-together.within-page&quot;&gt;always&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;p&quot;&gt;
  &lt;fo:block xsl:use-attribute-sets=&quot;p&quot;&gt;
        &lt;xsl:apply-templates /&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;
</program>
<p>The templates are simple, and is only to transform into fo:block. The indent in the begining 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.
</p><page />
<div class="column">
<p>This is the case that one line has the width of 21em.
</p>
<fo><fo:block font-size="1.0em"><fo:block-container width="21em" padding="1em"><fo:block text-indent="1em" space-before="0.6em" space-after="0.6em" text-align="justify" keep-together.within-page="always" border="dashed" border-color="red" border-width="thin">This is the sample of a paragragph. The paragraph is transformed into fo:block. Specify that one character is indented by text-indent="1em". Specify that the content is to be expanded to both edges by text-align="justify". But the last sentence of the last paragraph is left justified. It's because the default value of text-indent-last is text-align="justifiy", it is justified automatically.
</fo:block></fo:block-container></fo:block>
</fo>

<p> In case that one line has the width of 25em.</p>
<fo><fo:block font-size="1.0em"><fo:block-container width="25em" padding="1em"><fo:block text-indent="1em" space-before="0.6em" space-after="0.6em" text-align="justify" keep-together.within-page="always" border="dashed" border-color="red" border-width="thin">This is the sample of paragragph. The paragraph is transformed into fo:block. Specify that one character is indented by text-indent="1em". Specify that the content is to be expanded to both edges by text-align="justify". But the last sentence of the last paragraph is left justified. It's because the default value of text-indent-last is text-align="justifiy", it is justified automatically.</fo:block></fo:block-container></fo:block>
</fo>
</div>
</subsection>

<subsection><title>
The figure Element
</title><p>Figure elements are transformed into fo:external-graphic. The following shows the templates that process figure elements.
</p>
<program><title>Templates that process the figure elements
</title>&lt;xsl:attribute-set name=&quot;figure.title&quot; &gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;sans-serif&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align&quot;&gt;center&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;3pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;10pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-weight&quot;&gt;bold&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;keep-with-previous.within-page&quot;&gt;always&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;figure&quot;&gt;
  &lt;fo:block text-align=&quot;center&quot;&gt;
    &lt;fo:external-graphic src=&quot;{@src}&quot;&gt;
      &lt;xsl:if test=&quot;@width and @height&quot;&gt;
        &lt;xsl:attribute name=&quot;content-width&quot; &gt;
          &lt;xsl:value-of select=&quot;@width&quot;/&gt;
        &lt;/xsl:attribute&gt;
        &lt;xsl:attribute name=&quot;content-height&quot; &gt;
          &lt;xsl:value-of select=&quot;@height&quot;/&gt;
        &lt;/xsl:attribute&gt;
      &lt;/xsl:if&gt;
    &lt;/fo:external-graphic&gt;
  &lt;/fo:block&gt;
  &lt;fo:block xsl:use-attribute-sets=&quot;figure.title&quot;&gt;
  &lt;xsl:value-of select=&quot;title&quot; /&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;
</program>
<p>fo:external-graphic is generated and path of the figure is specified by the src attribute of figure element. In case the size of the figure is specified by the width, height attributes, put them in content-width, content-height. Antenna House XSL Formatter can treat image file formats such as BMP, EMF, WMF, JPEG.

</p>
</subsection>

<subsection><title>
The program Element
</title><p>
The program elements are transformed into fo:block and desplay the fonts in monospace. The following shows the templates.

</p>
<program><title>Templates that process the program elements
</title>&lt;xsl:attribute-set name=&quot;program&quot;&gt;
  &lt;xsl:attribute name=&quot;white-space&quot;&gt;pre&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;wrap-option&quot;&gt;wrap&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;background-color&quot;&gt;gainsboro&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;monospace&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-size&quot;&gt;9pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;padding&quot;&gt;0.5em&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;program.title&quot; &gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;sans-serif&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align&quot;&gt;center&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;3pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-weight&quot;&gt;bold&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;keep-with-next.within-page&quot;&gt;always&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;0.5em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;0.5em&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;program&quot;&gt;
  &lt;xsl:apply-templates select=&quot;title&quot;/&gt;
    &lt;fo:block xsl:use-attribute-sets=&quot;program&quot;&gt;
      &lt;xsl:apply-templates select=&quot;text()&quot;/&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;</program>
<p> 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(). But there are no templates to process text nodes (match=&quot;program/text()&quot;). So they are processed by the built-in template in XSLT in order to process only text node.
The following are important properties that apply to fo:block.
</p><ul><li>
Specify monospace in the font-family.
</li><li>
Specify white-space as pre. This has four meanings as follows.
<ol><li>linefeed-treatment=&quot;preserve&quot;：Line feed character (#xA) is preserved. Do not treat as space, or ignore.
</li><li>space-treatment=&quot;preserve&quot;：Characters classified as white space in XML except for #xA are preserved.
<note>White space in XML has space(#x20), tab(#x9), carriage return(#xD), linefeed(#xA). The treatment of #xA is specified by linefeed-treatment
</note></li><li>white-space-collapse=&quot;false&quot;：White spaces after processing by linefeed-treatment, space-treatment are not collapsed.
</li><li>wrap-option=&quot;no-wrap&quot;：No line-wrapping will occur if the line overflows.
</li></ol></li><li>Specify wrap-option as wrap. The line wraps if the line overflows.
<note>wrap-option=&quot;wrap&quot; is a default value. But it changes to wrap-option=&quot;no-wrap&quot; by specifying white-space=&quot;pre&quot;.  This property overide wrap-option="no-wrap" by wrap-option ="wrap"</note></li></ul><p>
According to these specifications the text in the program element is formatted as pre-formatted text.
</p>
</subsection>

<subsection><title>
The div Element
</title><p>The div element(general block element) simply transforms into fo:block with no properties. The templates are shown below.

</p>
<program><title>Template that processes the div element.
</title>&lt;xsl:template match=&quot;div&quot;&gt;
  &lt;fo:block&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;
</program>
<p>
The example of applying the div element is as follows. This sample stores formatting object directly to the div element and output it.
</p>
<program><title>
Example:
</title>&lt;xsl:attribute-set name=&quot;div.fo&quot; &gt;
  &lt;xsl:attribute name=&quot;border&quot;&gt;solid&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;border-width&quot;&gt;thin&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;padding&quot;&gt;1em&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;div[@class = &apos;fo&apos;]&quot;&gt;
  &lt;fo:block xsl:use-attribute-sets=&quot;div.fo&quot;&gt;
    &lt;xsl:copy-of select=&quot;node()&quot; /&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;
</program>
<p>The template specifies to copy all the descendants of the div element directly to the output by &lt;xsl:copy-of select=&quot;node()&quot; /&gt;. In order to use this function, specify fo namespace to the doc element. 
</p>
<program>&lt;doc xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot;&gt;
</program>

<p>Below shows how to use.
</p>
<div class="column">
<div>
&lt;div class=&quot;fo&quot;&gt;&lt;fo:block&gt;This is the &lt;fo:inline font-weight=&quot;bold&quot;&gt;example&lt;/fo:inline&gt; of embedding&lt;fo:inline font-size=&quot;1.5em&quot; text-decoration=&quot;underline&quot; font-style=&quot;italic&quot; font-weight=&quot;bold&quot;&gt;FO (Formatting Object).&lt;/fo:inline&gt;&lt;fo:inline background-color=&quot;#DDDDDD&quot;&gt;You can format the styles as you like,&lt;/fo:inline&gt; free from the &lt;fo:inline font-size=&quot;1em&quot;&gt;s&lt;/fo:inline&gt;&lt;fo:inline font-size=&quot;1.2em&quot;&gt;t&lt;/fo:inline&gt;&lt;fo:inline font-size=&quot;1.4em&quot;&gt;y&lt;/fo:inline&gt;&lt;fo:inline font-size=&quot;1.6em&quot;&gt;l&lt;/fo:inline&gt;&lt;fo:inline font-size=&quot;1.8em&quot;&gt;e&lt;/fo:inline&gt;&lt;fo:inline font-size=&quot;2.0em&quot;&gt;s&lt;/fo:inline&gt;&lt;fo:inline font-size=&quot;2.2em&quot;&gt;h&lt;/fo:inline&gt;&lt;fo:inline font-size=&quot;2.4em&quot;&gt;e&lt;/fo:inline&gt;&lt;fo:inline font-size=&quot;2.6em&quot;&gt;e&lt;/fo:inline&gt;&lt;fo:inline font-size=&quot;2.8em&quot;&gt;t&lt;/fo:inline&gt;limitation. But it is very&lt;fo:inline font-size=&quot;3em&quot; font-weight=&quot;bold&quot; font-family=&quot;sans-serif&quot;&gt;troublesome&lt;/fo:inline&gt;to write Fo directly．&lt;/fo:block&gt;&lt;/div&gt;
</div>
</div>
<p>
It is shown as follows:
</p><div class="column">
<div>
<div class="fo"><fo:block>This is the <fo:inline font-weight="bold">example</fo:inline> of embedding<fo:inline font-size="1.5em" text-decoration="underline" font-style="italic" font-weight="bold">FO (Formatting Object).</fo:inline><fo:inline background-color="#DDDDDD">You can format the styles as you like,</fo:inline> free from the <fo:inline font-size="1em">s</fo:inline><fo:inline font-size="1.2em">t</fo:inline><fo:inline font-size="1.4em">y</fo:inline><fo:inline font-size="1.6em">l</fo:inline><fo:inline font-size="1.8em">e</fo:inline><fo:inline font-size="2.0em">s</fo:inline><fo:inline font-size="2.2em">h</fo:inline><fo:inline font-size="2.4em">e</fo:inline><fo:inline font-size="2.6em">e</fo:inline><fo:inline font-size="2.8em">t</fo:inline>limitation. But it is very<fo:inline font-size="3em" font-weight="bold" font-family="sans-serif">troublesome</fo:inline>to write Fo directly．</fo:block></div>
<hidden>
This is the example of embedding FO(formatting object) into the document directly.
You can format the style as you like, free from the stylesheet limitaion.
Therefore, it is very troublesome to write Fo directly.</hidden>
 
</div>
</div>


</subsection>
</section>

<section logo="XSLFormatter.bmp"><title>
Processing table Elements
</title>
<div class="column">
<title>Output specification
</title>
<ul>
<li>
The descendants and self of a table element in the XML source document create a table formatting object.
</li>
<li>
The background color of the  head in the table is gray to descriminate from the contents in the table. And the line is solid, the line width is 1 pt.
</li>
<li>Cells in the table store the cell data placing the paddings which size is 0.3 x fontsize on the left, 0.2 x fontsize on the right. 
</li>
<li>

Process attributes specifying other format of the table.
<ol><li>
layout attribute, width attribute,rowheight attribute of the table element.
</li><li>
number attribute, width attribute of the col element </li>
<li>

height attribute of the tr element

</li><li>

align attribute, valign attribute, colspan attribute, rowspan attribute defined for th, td elements.

</li>
</ol></li></ul></div>

<subsection>
<title>
Comparing the SampleDoc Table with XSL Table 
</title>
<p>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 SampleDoc table with XSL table. First of all, the SampleDoc table is as follows:
</p><table rowheight="2em">
<col width="17.5%"/><col width="22.5%"/><col width="60%"/><thead><tr height="1em"><th align="center"> element</th><th align="center"> mean</th><th align="center"> definition</th></tr></thead><tbody><tr><td>table<br/></td><td> entire table</td><td>(title?, col*, thead?, tfoot?, tbody)<br/>Specify whether the table layout is formatted automatically or it is fixed, in the layout attribute.The entire width is specified in the width attribute, the entire height of the table is specified in the row height attribute.
</td></tr>
<tr><td>col<br/></td><td> column attribute</td><td>EMPTY<br/>
The column width is specified in the width attribute, the column number is specified in the number attribute.

</td></tr>
<tr><td>thead</td><td> table header</td><td>(tr*)</td></tr><tr><td>tfoot</td><td> table footer</td><td>(tr*)</td></tr><tr><td>tbody</td><td> table body</td><td>(tr*)</td></tr><tr><td>tr</td><td> table row</td><td>(th | td)*<br />The height of the row is specified in the height attribute.
</td></tr><tr><td>th</td><td> table header cell</td><td>
(a group of inline elements)*
<br/>
The number of the rows to be expanded accross is specified in the colspan attribute, the number of the rows to be expanded down is specified in the rowspan. The align,valign attributes allows horizontal, vertical alignment to be set. 
</td></tr><tr><td>td</td><td> table data cell</td><td>
(a group of inline elements)*
<br/>The number of the rows to be expanded accross is specified in the colspan attribute, the number of the rows to be expanded down is specified in the rowspan. The align, valign attributes allows horizontal, vertical alignment to be set. 
</td></tr>
</tbody></table>
<p>
While, table of XSL consists of the following objects.
</p><table rowheight="2em"><col width="17.5%"/><col width="22.5%"/><col width="60%"/><thead><tr height="1em"><th align="center"> Element</th><th align="center"> Meaning</th><th align="center"> Definition</th></tr></thead><tbody><tr><td>fo:table-and-caption</td><td>
The whole table and the caption
</td><td>(table-caption?, table)</td></tr><tr><td>fo:table-caption</td><td>The caption of the table</td><td>(%block;)<note>
%block; is defined to contain block, block-container, table-and-caption, table, list-block in the XSL Specificaion. Generally, it is fo:block, fo:block-container.
</note>
</td></tr><tr><td>fo:table</td><td>
The grid composed of cells except caption cells. 
</td><td>(fo:table-column*, fo:table-header?, fo:table-footer?, fo:table-body+)<br/>
table-layout：Specify automatical table layout or fixed layout.<br/>table-omit-header-at-break：Specify whether to omit placing header or not when the page breaks.<br/>table-omit-footer-at-break：Specify whether to omit placing footer or not when the page breaks.</td></tr><tr><td>fo:table-column</td><td>
Define the feature of the table column
</td><td>EMPTY<br/>
column-number：The number of columns
<note>Use as a parmeter of from-table-column() function.
</note>
<br />column-width：The width of the column<br />
number-columns-repeated：The number of columns specifying the repetition of the table-column. <br />number-colums-spanned：The number of columns spanned by table-cells.<note>Refer to from-table-column() function.
</note>
</td></tr><tr><td>fo:table-header</td><td>
Table header
</td><td>(fo:table-row+|fo:table-cell+)</td></tr><tr><td>fo:table-footer</td><td>
Table footer
</td><td>(fo:table-row+|fo:table-cell+)</td></tr><tr><td>fo:table-body</td><td>
Table body
</td><td>(fo:table-row+|fo:table-cell+)</td></tr><tr><td>fo:table-row</td><td>Table row
</td><td>(fo:table-cell+)</td></tr><tr><td>fo:table-cell</td><td>
Table cell
</td><td>(%block;)+<br/>
number-columns-spanned：The number of columns spanned by table-cells.<br />
number-rows-spanned : The number of rows spanned. </td></tr></tbody></table><p><figure src="table-structen.emf"><title>
Table structure of SampleDoc, XSL-FO</title></figure>
</p><p>Comparing these two, they have almost the same structure. Transforming into tables is basically considered to exchange the structure to another.
</p>
</subsection>

<subsection>
<title>
Table Processing Templates
</title>
<p>
Templates that process table are shown below.
</p>

<program><title>
Definition of the table properties</title>
&lt;xsl:attribute-set name=&quot;table.data&quot; &gt;
  &lt;xsl:attribute name=&quot;table-layout&quot;&gt;fixed&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;10pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;10pt&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;table.data.caption&quot; &gt;
  &lt;xsl:attribute name=&quot;font-family&quot;&gt;sans-serif&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;text-align&quot;&gt;start&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;3pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;3pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after.precedence&quot;&gt;2&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;font-weight&quot;&gt;bold&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;keep-with-next.within-page&quot;&gt;always&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;table.data.th&quot; &gt;
  &lt;xsl:attribute name=&quot;background-color&quot;&gt;#DDDDDD&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;border-style&quot;&gt;solid&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;border-width&quot;&gt;1pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;padding-start&quot;&gt;0.3em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;padding-end&quot;&gt;0.2em&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;table.data.td&quot; &gt;
  &lt;xsl:attribute name=&quot;border-style&quot;&gt;solid&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;border-width&quot;&gt;1pt&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;padding-start&quot;&gt;0.3em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;padding-end&quot;&gt;0.2em&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;
</program><program><title>
Templates that process the table</title>&lt;xsl:template match=&quot;table&quot;&gt;
  &lt;fo:table-and-caption &gt;
    &lt;xsl:if test=&quot;title&quot;&gt;
      &lt;fo:table-caption xsl:use-attribute-sets=&quot;table.data.caption&quot;&gt;
        &lt;fo:block start-indent=&quot;0em&quot;&gt;
          &lt;xsl:apply-templates select=&quot;title&quot; mode=&quot;make-title&quot;/&gt;
       &lt;/fo:block&gt;
      &lt;/fo:table-caption&gt;
    &lt;/xsl:if&gt;
    &lt;fo:table xsl:use-attribute-sets=&quot;table.data&quot;&gt;
      &lt;xsl:if test=&quot;@layout&quot;&gt;
        &lt;xsl:attribute name=&quot;table-layout&quot;&gt;
          &lt;xsl:value-of select=&quot;@layout&quot;/&gt;
        &lt;/xsl:attribute&gt;
      &lt;/xsl:if&gt;
      &lt;xsl:if test=&quot;@width&quot;&gt;
        &lt;xsl:attribute name=&quot;inline-progression-dimension&quot;&gt;
          &lt;xsl:value-of select=&quot;@width&quot;/&gt;
        &lt;/xsl:attribute&gt;
      &lt;/xsl:if&gt;
      &lt;xsl:apply-templates /&gt;
    &lt;/fo:table&gt;
  &lt;/fo:table-and-caption&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;table/tltle&quot; mode=&quot;make-title&quot;&gt;
  &lt;xsl:apply-templates /&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;table/tltle&quot;&gt;
&lt;/xsl:template&gt;&lt;xsl:template match=&quot;col&quot;&gt;
  &lt;fo:table-column column-number=&quot;{@number}&quot; column-width=&quot;{@width}&quot; /&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;thead&quot;&gt;
  &lt;fo:table-header&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:table-header&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;tfoot&quot;&gt;
  &lt;fo:table-footer&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:table-footer&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;tbody&quot;&gt;
  &lt;fo:table-body&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:table-body&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;tr&quot;&gt;
  &lt;xsl:element name=&quot;fo:table-row&quot;&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;@height&quot;&gt;
        &lt;xsl:attribute name=&quot;block-progression-dimension&quot;&gt;
          &lt;xsl:value-of select=&quot;@height&quot;/&gt;
        &lt;/xsl:attribute&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:if test=&quot;(ancestor::*)[2]/@rowheight&quot;&gt;
          &lt;xsl:attribute name=&quot;block-progression-dimension&quot;&gt;
            &lt;xsl:value-of select=&quot;(ancestor::*)[2]/@rowheight&quot;/&gt;
          &lt;/xsl:attribute&gt;
        &lt;/xsl:if&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/xsl:element&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;th&quot;&gt;
  &lt;fo:table-cell xsl:use-attribute-sets=&quot;table.data.th&quot;&gt;
    &lt;xsl:call-template name=&quot;cell-span&quot;/&gt;
    &lt;xsl:if test=&quot;@valign&quot;&gt;
      &lt;xsl:attribute name=&quot;display-align&quot;&gt;
        &lt;xsl:value-of select=&quot;@valign&quot;/&gt;
      &lt;/xsl:attribute&gt;
    &lt;/xsl:if&gt;
    &lt;fo:block &gt;
      &lt;xsl:if test=&quot;@align&quot;&gt;
        &lt;xsl:attribute name=&quot;text-align&quot;&gt;
          &lt;xsl:value-of select=&quot;@align&quot;/&gt;
        &lt;/xsl:attribute&gt;
      &lt;/xsl:if&gt;
      &lt;xsl:apply-templates /&gt;
    &lt;/fo:block&gt;
  &lt;/fo:table-cell&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;td&quot;&gt;
  &lt;fo:table-cell xsl:use-attribute-sets=&quot;table.data.td&quot;&gt;
    &lt;xsl:call-template name=&quot;cell-span&quot;/&gt;
    &lt;xsl:if test=&quot;@valign&quot;&gt;
      &lt;xsl:attribute name=&quot;display-align&quot;&gt;
        &lt;xsl:value-of select=&quot;@valign&quot;/&gt;
      &lt;/xsl:attribute&gt;
    &lt;/xsl:if&gt;
    &lt;fo:block &gt;
      &lt;xsl:if test=&quot;@align&quot;&gt;
        &lt;xsl:attribute name=&quot;text-align&quot;&gt;
          &lt;xsl:value-of select=&quot;@align&quot;/&gt;
        &lt;/xsl:attribute&gt;
      &lt;/xsl:if&gt;
      &lt;xsl:apply-templates /&gt;
    &lt;/fo:block&gt;
  &lt;/fo:table-cell&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name=&quot;cell-span&quot;&gt;
  &lt;xsl:if test=&quot;@colspan&quot;&gt;
    &lt;xsl:attribute name=&quot;number-columns-spanned&quot;&gt;
      &lt;xsl:value-of select=&quot;@colspan&quot;/&gt;
    &lt;/xsl:attribute&gt;
  &lt;/xsl:if&gt;
  &lt;xsl:if test=&quot;@rowspan&quot;&gt;
    &lt;xsl:attribute name=&quot;number-rows-spanned&quot;&gt;
      &lt;xsl:value-of select=&quot;@rowspan&quot;/&gt;
  &lt;/xsl:attribute&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;
</program>

<p>
The stylesheet looks long, though, it is only to map the element name of the SampleDoc to that of XSL formatting object. Below shows the points.
</p>
<ol>
<li>
Layout attributes defined for the table element is set for fo:table layout property to control the autmatic table layouts (the value auto or fixed is varid).
<note>Antenna House XSL Formatter V1.1 dosen't support auto table formatting. Even if it is speicfied as "auto", the layout will be fixed.
</note>
</li>
<li>The width attribute defined for the table element is set for inline-progression-dimension property of fo:table object as the width of the entire table. 
</li><li>The number, width attributes defined for the col element is set for column-number, column-width property of the fo:table-column object. Then, the column width can be specified. It's possible to specify the column width not by the fixed number but by % value. There are various ways to specify parameter, such as specifying an absolute value to the width attribute of the table element, or specifying the width of the table column as % value.
<note>Furthermore, there is a way to specify an absolute value for a part of the columns, while, specify proportional-column-width() function to the rest of the columns and share width of the cells proportionally. </note></li><li>The row height attribute defined for the table element is set to block-progression-dimension of fo:table-row object. The attribute refer to the template that process tr element, so it's specified as &quot;(ancestor::*)[2]/@rowheight&quot;
</li>
<li>The height attribute defined for the tr element is set for block-progression-dimension of the fo:table-row object. It is also set to precede the rowheight attribute defined for the table element. 

</li>
<li>
The colspan, rowspan attributes defined for the th, td elements are set to each number-columns-spanned, number-rows-spanned of fo:table-cell object. Then, cells can be spanned in this way. In addition, the align, valign attributes are set to text-align property, display-align property of fo:table-cell in fo:block. In this way the text in the cell can be aligned.
</li>
</ol>
</subsection>

<page/>
<subsection>
<title>Example of Table Construction
</title>
<p>Below is an example of table construction.
</p>
<div class="column">
<p>
When nothing are specified. the width of the column is devided by ther number of the column equally.
</p><table>
<thead><tr>
<th>
Symbol
</th>
<th>
How to read
</th>
<th>
Meaning
</th>
</tr></thead><tbody><tr>
<td>|</td>
<td>
vertical bar
</td>
<td>
Means one element or another is to be used.
</td>
</tr><tr>
<td>?</td>
<td>
question mark
</td>
<td>
Means that the element appears zero or one time.
</td>
</tr><tr>
<td>,</td>
<td> comma </td>
<td>Means that elements appear in the same order in that element inside the document.
</td>
</tr><tr>
<td>*</td>
<td>asterisk</td>
<td>
Means that the element appears zero or more times.
</td>
</tr><tr>
<td>+</td>
<td> plus</td>
<td>
Means that the element appears one or more time.
</td>
</tr><tr>
<td>()</td>
<td> parentheses</td>
<td>
Means to group plural numbers of elements in the parentheses.</td>
</tr><tr>
<td></td>
<td>
empty
</td>
<td>
means that only one element can be described.
</td>
</tr></tbody></table>
<p>Specify the column width by the col element. Set 10%, 20%, 40% from the left. Specify height=&quot;1em&quot; in the tr element in order to set the height 1em only for the table header. 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=&quot;center&quot; align=&quot;center&quot; 

</p><table rowheight="2em">
<col width="10%"/><col width="20%"/><col width="40%"/><thead><tr height="1em">
<th align="center"> Symbol</th>
<th align="center"> How to read</th>
<th align="center"> Meaning</th>
</tr></thead><tbody><tr>
<td valign="center" align="center">|</td>
<td valign="center" align="center"> Vertical bar</td>
<td>
Means one element or another is to be used.
</td>
</tr><tr>
<td valign="center" align="center">?</td>
<td valign="center" align="center"> question mark</td>
<td>
Means that the element appears zero or one time.
</td>
</tr><tr>
<td valign="center" align="center">,</td>
<td valign="center" align="center"> comma</td>
<td>
Means that that elements appear in the same order in that element inside the document.
</td>
</tr><tr>
<td valign="center" align="center">*</td>
<td valign="center" align="center"> asterisk</td>
<td>
Means that the element appears zero or more times.</td>
</tr><tr>
<td valign="center" align="center">+</td>
<td valign="center" align="center"> plus</td>
<td>
Means that the element appears one or more time.</td>
</tr><tr>
<td valign="center" align="center">()</td>
<td valign="center" align="center"> parentheses</td>
<td>
Means to group plural numbers of elements in the parentheses.</td>
</tr><tr>
<td></td>
<td valign="center" align="center">empty</td>
<td>
Only one element can be described.
</td>
</tr></tbody></table>

</div>
</subsection>
</section>




<section logo="XSLFormatter.bmp">
<title>Processing list Elements
</title>
<div class="column">
<title>
Output specification
</title>
<ul>
<li>
The list elements (ol,ul,dl) of the sampleDoc is formatted as the table that the label and the body of the list are lined in horizontal mode. 
</li>
<li>
But, the dt element also make it possible to be formatted such as the label and the body of the list are lined in vertical mode.
<note>This is the same desplay format as the  browser format of dt in HTML. 

</note></li>
<li>The ordered list element (ol) make it possible to take various types of numbers that are set in the labels.

</li>
<li>
The unordered list elements (ul) make it possible to specify various types of bullets that are set in the labels. 
</li>
</ul>
</div>

<subsection>
<title>
Comparing the List of SampleDoc with the List of XSL
</title>
<p>
In order to put the list elements to both the label of the list and body of the list, it is neccessaly to transform them to fo:list-block in XSL.
Let us compare lists of SampleDoc with those of XSL formatting objects.
</p>
<table rowheight="2em">
<col width="17.5%"/><col width="22.5%"/><col width="60%"/><thead>
<tr><th align="center"> Element </th><th align="center"> Meaning</th><th align="center"> Definition</th></tr>
</thead>
<tbody><tr><td>ol</td><td>ordered list</td><td>(li)* </td>
</tr>
<tr>
<td>ul</td><td>unordered list</td><td>(li)* </td>
</tr>
<tr>
<td>li</td><td>list item</td><td>
(a group of inline elements)* </td>
</tr>
<tr>
<td>dl</td><td>definition list</td><td>(dt, dd)*</td>
</tr>
<tr>
<td>dt</td><td>definition term</td><td>
(a group of inline elements)*</td>
</tr>
<tr>
<td>dd</td><td>definition details</td><td> 
(a group of inline elements)*
</td>
</tr>
</tbody>
</table>
<p>
While, the list of XSL is as follows:
</p>
<table rowheight="2em">
<col width="17.5%"/><col width="22.5%"/><col width="60%"/><thead>
<tr height="1em">
<th> Element</th><th> Meaning</th><th> Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td>list-block</td><td>
The formatting object that format the lists
</td><td>(list-item+)<br/>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.

<br/>
provisional-label-separation：Specify the  distance between the end of the list-item-label and the start of the list item body.
</td>
</tr>
<tr>
<td>list-item</td><td>
Express one list item, including list label and list body.
</td><td>(list-item-label,list-item-body)
</td>
</tr>
<tr>
<td>list-item-label</td><td>Express the label of a list item.
</td><td>(%block;)+</td>
</tr>
<tr>
<td>list-item-body</td><td>
Express the body of a list item.
</td><td>(%block;)+</td>
</tr>
</tbody>
</table>
<p>
Shown below is the structure of the both lists
</p>
<figure src="list-struct-en.emf"><title>The lists of SampleDoc and XSL
</title></figure>
<p>
The followings are remarkable diferences between two.
</p><ul><li>
The bullets in the label are autmatically generated by the ul,ol elements in HTML. In XSL, they have to be generated within the list-item-label region using a stylesheet.
</li><li>In order to transform the definition list element into a fo:list-block object, set the dt content in the fo:list-item-label and the dd content in the fo:list-item-body.
</li><li>
There is no function to calculate the width of the fo:list-item-label formatting object. An appropriate value must be specified in the XSLT stylesheet.
</li></ul><p>
Each of the XSLT stylesheet is shown below:
</p>
</subsection>


<subsection><title>
Templates that Process the Ordered List.
</title><program><title>
The ol templates for ordered list
</title>
&lt;xsl:param name=&quot;list-startdist-default&quot; select=&quot;string(&apos;2em&apos;)&quot;/&gt;
&lt;xsl:param name=&quot;list-gap-default&quot; select=&quot;string(&apos;0.5em&apos;)&quot;/&gt;

&lt;xsl:attribute-set name=&quot;list.item&quot; &gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;0.4em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;0.4em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;relative-align&quot;&gt;baseline&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;ol&quot;&gt;
  &lt;!-- determine the distance between the start  of the list-item-label and the start of the list-item-body, the distance between the end of the list-item-label and the start of the list-item-body. --&gt;
  &lt;xsl:variable name=&quot;start-dist-local&quot;&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;./@startdist&quot;&gt;
        &lt;xsl:value-of select=&quot;./@startdist&quot;/&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select=&quot;$list-startdist-default&quot;/&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:variable name=&quot;gap-local&quot;&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;./@gap&quot;&gt;
        &lt;xsl:value-of select=&quot;./@gap&quot;/&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select=&quot;$list-gap-default&quot;/&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:variable&gt;

  
  &lt;!-- generate fo:list-block --&gt;
  &lt;fo:list-block provisional-distance-between-starts=&quot;{$start-dist-local}&quot;  provisional-label-separation=&quot;{$gap-local}&quot; &gt;
    &lt;!-- Process the descendants of li --&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/fo:list-block&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;ol/li&quot;&gt;
  &lt;fo:list-item  xsl:use-attribute-sets=&quot;list.item&quot;&gt;
    &lt;!-- generate list-item-label--&gt;
    &lt;!-- the end position of the list-item-label is calculated by label-end() function --&gt;
    &lt;!-- label format is specified in the type attribute. The initial value is '1'.--&gt;
    &lt;fo:list-item-label end-indent=&quot;label-end()&quot;&gt;
      &lt;fo:block text-align=&quot;end&quot;&gt;
        &lt;xsl:choose&gt;
          &lt;xsl:when test=&quot;../@type&quot;&gt;
            &lt;xsl:number format=&quot;{../@type}&quot;/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
            &lt;xsl:number format=&quot;1.&quot;/&gt;
          &lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
      &lt;/fo:block&gt;
    &lt;/fo:list-item-label&gt;
       &lt;!-- generate the list-item-body --&gt;   
    &lt;!-- The start position of the list-item-label is calculated by body-start() function --&gt;
    &lt;fo:list-item-body start-indent=&quot;body-start()&quot;  text-align=&quot;justify&quot; &gt;
      &lt;fo:block&gt;   
        &lt;!-- the descendants of li are specified by the descendants of templates. --&gt;
        &lt;xsl:apply-templates/&gt;
      &lt;/fo:block&gt;
    &lt;/fo:list-item-body&gt;
  &lt;/fo:list-item&gt;
&lt;/xsl:template&gt;
</program>
<subsubsection><title>
Specify the positions of the label and the body.
</title><p>When formatting a list, it is important to arrange the label and the body. In the fo:list-block:
</p><ul><li>provisional-distance-between-starts specifies the distance between the start of the list-item-label and the start of the list-item-body

</li>
<li>provisional-label-separation specifies the distance between the end of the list-item-label and the start of the list-item-body. 
</li></ul>
<p type="continue">The template specifies these to apply to the startdist, gap attributes of the ol element. But actually the descendants of the fo:list-item are formatted.
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.
<note>These are called 'Proterty Value Function' in the XSL Specification.
</note>
These two functions count the position by refering the values of provisional-distance-between-starts, provisional-distance-between-starts specified in fo:list-block.
<note> 
label-end() =  the list item width of fo:list-block -  (provisional-distance-between-starts + start-indent of the label - provisional-label-separation) 

<br/>

body-start() =start-indent of the label + provisional-distance-between-starts
</note>
</p><p>These function specification is just a manner. If you understand how to layout lists, it may be no problem to apply these mechanically.
 
</p></subsubsection><subsubsection><title>
Label format
</title><p>The list label consists of a sequence of numbers. A sequence of numbers is generated by the default  &lt;xsl:number format=&quot;1.&quot;/&gt;. xsl:number counts the same level (sibling) of the li elements in the XML source document, returns a sequence number of the current li elements. Therefore li elements are processed correctly eve if the lists are nested.  
</p><figure src="ol-labelnumber-en.emf"><title>
Format the ordered list label processed by xsl:number
</title></figure><p>
Form of a sequence of numbers is specified by the type attribute of the ol element. An ordered list can take various kinds of types.
<table><col width="15%"/>
<col width="40%"/><thead><tr><th> Form</th><th> Output</th></tr></thead><tbody><tr><td>1</td><td>1,2,3,4...</td></tr><tr><td>01</td><td>01,02,03,04...</td></tr><tr><td>a</td><td>a,b,c,d,...x,y,z,aa,ab,ac...</td></tr><tr><td>A</td><td>A,B,C,D,...X,Y,Z,AA,AB,AC...</td></tr><tr><td>ア</td><td>ア,イ,ウ,エ...</td></tr><tr><td>あ</td><td>あ,い,う,え...</td></tr><tr><td>イ</td><td>イ,ロ,ハ,ニ...</td></tr><tr><td>一</td><td>一,二,三,四...</td></tr><tr><td>壱</td><td>壱,弐,参,四...</td></tr></tbody></table>The format attribute specifies the characters that  represent zero, 1 in UNICODE, and other parentheses. As the format of label can be specified in the XML source document, the document can be made flexibly.

</p></subsubsection><subsubsection><title>Example of ordered list
</title><program><title>
XML source data
</title>&lt;ol type=&quot;a.&quot;&gt;
  &lt;li&gt;kind of list
    &lt;ol type=&quot;一.&quot;&gt;
      &lt;li&gt;unordered list&lt;/li&gt;
      &lt;li&gt;ordered list&lt;/li&gt;
      &lt;li&gt;definition list&lt;/li&gt;
    &lt;/ol&gt; 
  &lt;/li&gt;
  &lt;li&gt;list element
    &lt;ol&gt;
      &lt;li&gt;row&lt;/li&gt; 
      &lt;li&gt;column&lt;/li&gt; 
      &lt;li&gt;cell&lt;/li&gt;
    &lt;/ol&gt; 
  &lt;/li&gt;
  &lt;li&gt;block element and inline element&lt;/li&gt;
&lt;/ol&gt;
</program><p>
Following is the output result.
</p><div class="fo">
<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="0.5em">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">a.</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block> kind of list
<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="0.5em">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">一.</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>unordered list</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">二.</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>ordered list</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">三.</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>definition list</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">b.</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>list element<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="0.5em">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">1.</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>row</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">2.</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>column</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">3.</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>cell</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">c.</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>block element and inline element</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</div></subsubsection></subsection>

<subsection><title>
Templates that Process the Unordered List
</title><program><title>
Templates of unordered list
</title>&lt;xsl:param name=&quot;list-startdist-default&quot; select=&quot;string(&apos;2em&apos;)&quot;/&gt;
&lt;xsl:param name=&quot;list-gap-default&quot; select=&quot;string(&apos;0.5em&apos;)&quot;/&gt;
&lt;xsl:attribute-set name=&quot;list.item&quot; &gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;0.4em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;0.4em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;relative-align&quot;&gt;baseline&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;ul&quot;&gt;
  &lt;!-- determine the distance between the start of the list-iten-label and the start of the list-item-body, the distance between the end of the list-item-label and the start of the list-item-body. --&gt;
  &lt;xsl:variable name=&quot;start-dist-local&quot;&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;./@startdist&quot;&gt;
        &lt;xsl:value-of select=&quot;./@startdist&quot;/&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select=&quot;$list-startdist-default&quot;/&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:variable name=&quot;gap-local&quot;&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;./@gap&quot;&gt;
        &lt;xsl:value-of select=&quot;./@gap&quot;/&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select=&quot;$list-gap-default&quot;/&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:variable&gt;

  &lt;!-- Generate fo:list-block. --&gt;
  &lt;fo:list-block provisional-distance-between-starts=&quot;{$start-dist-local}&quot;  provisional-label-separation=&quot;{$gap-local}&quot; &gt;
    &lt;!-- Process the descendants of li --&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/fo:list-block&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;ul/li&quot;&gt;
  &lt;fo:list-item xsl:use-attribute-sets=&quot;list.item&quot; &gt;
      &lt;!-- Generate list label.--&gt;
      &lt;!-- The end position of the label is calculated by label-end()function. --&gt;
      &lt;!-- The characters for label of line are specified in the type attribute. Initial value is「・」 --&gt;
    &lt;fo:list-item-label end-indent=&quot;label-end()&quot;&gt;
      &lt;fo:block text-align=&quot;end&quot;&gt;
        &lt;xsl:choose&gt;
          &lt;xsl:when test=&quot;../@type=&apos;disc&apos;&quot;&gt;
            &lt;xsl:text&gt;●&lt;/xsl:text&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test=&quot;../@type=&apos;circle&apos;&quot;&gt;
            &lt;xsl:text&gt;○&lt;/xsl:text&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test=&quot;../@type=&apos;square&apos;&quot;&gt;
            &lt;xsl:text&gt;□&lt;/xsl:text&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test=&quot;../@type=&apos;bsquare&apos;&quot;&gt;
            &lt;xsl:text&gt;■&lt;/xsl:text&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
            &lt;xsl:text&gt;・&lt;/xsl:text&gt;
          &lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
      &lt;/fo:block&gt;
    &lt;/fo:list-item-label&gt;
    &lt;!-- Generate the list body.--&gt;
    &lt;!-- The starting position of the label is calculated by the body-start() function --&gt;
    &lt;fo:list-item-body start-indent=&quot;body-start()&quot; text-align=&quot;justify&quot; &gt;
      &lt;fo:block&gt;
        &lt;xsl:apply-templates/&gt;
      &lt;/fo:block&gt;
    &lt;/fo:list-item-body&gt;
  &lt;/fo:list-item&gt;
&lt;/xsl:template&gt;
</program>
<subsubsection><title>
Specify characters for label of line
</title><p>
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 attribute in the ul element.
</p><p>
This 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 attribute defined for the ul element.
</p><program><title>
The template that use a image as a character for label of line.
</title>
&lt;!-- The template that use a image as a character for label of line.--&gt;
&lt;xsl:template match=&quot;ul[substring(@type,1,4)=&apos;img:&apos;]/li&quot;&gt;
  &lt;fo:list-item  xsl:use-attribute-sets=&quot;list.item&quot; &gt;
    &lt;fo:list-item-label end-indent=&quot;label-end()&quot;&gt;
      &lt;fo:block text-align=&quot;end&quot;&gt;
        &lt;fo:external-graphic src=&quot;{substring-after(../@type,substring(../@type,1,4))}&quot; content-height=&quot;1.2em&quot; content-width=&quot;1.2em&quot;/&gt;
      &lt;/fo:block&gt;
    &lt;/fo:list-item-label&gt;
    &lt;fo:list-item-body start-indent=&quot;body-start()&quot; text-align=&quot;justify&quot; &gt;
      &lt;fo:block&gt;
        &lt;xsl:apply-templates/&gt;
      &lt;/fo:block&gt;
    &lt;/fo:list-item-body&gt;
  &lt;/fo:list-item&gt;
&lt;/xsl:template&gt;
</program></subsubsection><page /><subsubsection><title>
An example of unordered list
</title><p>
XML source data
</p><program>&lt;ul type=&quot;square&quot;&gt;
  &lt;li&gt;type of list
    &lt;ul type=&quot;disc&quot;&gt;
      &lt;li&gt;unordered list&lt;/li&gt;
      &lt;li&gt;ordered list&lt;/li&gt;
      &lt;li&gt;definition list&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;table element
    &lt;ul&gt;
      &lt;li&gt;row&lt;/li&gt;
      &lt;li&gt;column&lt;/li&gt;
      &lt;li&gt;cell&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt; block element and inline element&lt;/li&gt;
&lt;/ul&gt;
</program><p>
Folowing is the output result
</p>
<div class="fo">
<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="0.5em">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">□</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>kinds of list
<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="0.5em">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">●</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>unordered list</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">●</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>orered list</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">●</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>definition list</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">□</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>list element<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="0.5em">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">・</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>row</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">・</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>column</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">・</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>cell</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end">□</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>
block element and inline element
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</div>
<p>
XML source data
</p>
<program>&lt;ul type=&quot;img:bullet-leaf.png&quot;&gt;
  &lt;li&gt;type of list
    &lt;ul type=&quot;img:bullet-star.png&quot;&gt;
      &lt;li&gt;unordered list&lt;/li&gt; 
      &lt;li&gt;ordered list&lt;/li&gt;
      &lt;li&gt;definition list&lt;/li&gt;
    &lt;/ul&gt; 
  &lt;/li&gt;
  &lt;li&gt;list element
    &lt;ul type=&quot;img:bullet-blue-circle.png&quot;&gt;
      &lt;li&gt;row&lt;/li&gt;
      &lt;li&gt;column&lt;/li&gt;
      &lt;li&gt;cell&lt;/li&gt; 
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;block element and inlinte element&lt;/li&gt;
&lt;/ul&gt;
</program>
<p>Folowing is the output result
</p>
<div class="fo">
<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="0.5em">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end"><fo:external-graphic src="bullet-leaf.png" content-height="12pt" content-width="12pt"/></fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>type of list
<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="0.5em">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end"><fo:external-graphic src="bullet-star.png" content-height="12pt" content-width="12pt"/></fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>unordered list</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end"><fo:external-graphic src="bullet-star.png" content-height="12pt" content-width="12pt"/></fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>ordered list</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end"><fo:external-graphic src="bullet-star.png" content-height="12pt" content-width="12pt"/></fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>definition list</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end"><fo:external-graphic src="bullet-leaf.png" content-height="12pt" content-width="12pt"/></fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>list element<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="0.5em">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end"><fo:external-graphic src="bullet-blue-circle.png" content-height="12pt" content-width="12pt"/></fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>row</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end"><fo:external-graphic src="bullet-blue-circle.png" content-height="12pt" content-width="12pt"/></fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>column</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end"><fo:external-graphic src="bullet-blue-circle.png" content-height="12pt" content-width="12pt"/></fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block> cell</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"><fo:block text-align="end"><fo:external-graphic src="bullet-leaf.png" content-height="12pt" content-width="12pt"/></fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()" text-align="justify">
<fo:block>
block element and inline element
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</div>
</subsubsection></subsection>

<subsection><title>
Templates that Process the Definition List
</title>
<p>
The following problem occures when transforming the definition list into fo:list-block formatting object.
</p><ul><li>In the SampleDoc specification, child of dl element is supposed to appear in dt, dd order (dt,dd)*, but in HTML the condition is more relaxed. The pattern of only dt, only dd also exist.

<b>&lt;!ELEMENT DL (DT|DD)+ &gt;</b></li><li>dt can be mapped to fo:list-item-label, dd can be mapped to fo:list-item-body. But there are no tags to be mapped to generate fo:list-item in the XML source document.
</li></ul><p>
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 XSLT stylesheet described in the XSL specification.
</p>
<subsubsection><title>Templates of definition list
</title>
<program><title>Templates of definition list
</title>&lt;xsl:attribute-set name=&quot;dt&quot; &gt;
  &lt;xsl:attribute name=&quot;font-weight&quot;&gt;bold&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;dd.list&quot; &gt;
  &lt;xsl:attribute name=&quot;space-before&quot;&gt;0.3em&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name=&quot;space-after&quot;&gt;0.5em&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;dd.block&quot; use-attribute-sets=&quot;dd.list&quot;&gt;
  &lt;xsl:attribute name=&quot;start-indent&quot; &gt;inherit + 4em&lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;dl&quot;&gt;
  &lt;xsl:choose&gt;
    &lt;xsl:when test=&quot;@type=&apos;list&apos;&quot;&gt;
      &lt;xsl:call-template name=&quot;dl.format.list&quot; /&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;xsl:call-template name=&quot;dl.format.block&quot; /&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name=&quot;dl.format.block&quot;&gt;
  &lt;xsl:apply-templates /&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name=&quot;dl.format.list&quot;&gt;
  &lt;xsl:variable name=&quot;start-dist-local&quot;&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;./@startdist&quot;&gt;
        &lt;xsl:value-of select=&quot;./@startdist&quot;/&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select=&quot;$dl-startdist-default&quot;/&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:variable name=&quot;gap-local&quot;&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;./@gap&quot;&gt;
        &lt;xsl:value-of select=&quot;./@gap&quot;/&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select=&quot;$dl-gap-default&quot;/&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:variable&gt;

  &lt;fo:list-block provisional-distance-between-starts=&quot;{$start-dist-local}&quot;  provisional-label-separation=&quot;{$gap-local}&quot; &gt;
    &lt;xsl:call-template name=&quot;process.dl.list&quot;/&gt;
  &lt;/fo:list-block&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name=&quot;process.dl.list&quot;&gt;
  &lt;xsl:param name=&quot;dts&quot; select=&quot;/..&quot;/&gt;
  &lt;xsl:param name=&quot;dds&quot; select=&quot;/..&quot;/&gt;
  &lt;xsl:param name=&quot;nodes&quot; select=&quot;*&quot;/&gt;
  
  &lt;xsl:choose&gt;
    &lt;xsl:when test=&quot;count($nodes)=0&quot;&gt;
      &lt;!--  data end：Process the elements stocked in dts, dds. --&gt;
      &lt;xsl:if test=&quot;count($dts)&gt;0 or count($dds)&gt;0&quot;&gt;
        &lt;fo:list-item  xsl:use-attribute-sets=&quot;list.item&quot;&gt;
          &lt;fo:list-item-label end-indent=&quot;label-end()&quot;&gt;
            &lt;xsl:apply-templates select=&quot;$dts&quot;/&gt;
          &lt;/fo:list-item-label&gt;
          &lt;fo:list-item-body start-indent=&quot;body-start()&quot;&gt;
            &lt;xsl:apply-templates select=&quot;$dds&quot;/&gt;
          &lt;/fo:list-item-body&gt;
        &lt;/fo:list-item&gt;
      &lt;/xsl:if&gt;
    &lt;/xsl:when&gt;

    &lt;xsl:when test=&quot;name($nodes[1])=&apos;dd&apos;&quot;&gt;
      &lt;!-- dd is stored in dds fnction, call itself recursively.--&gt;
      &lt;xsl:call-template name=&quot;process.dl.list&quot;&gt;
        &lt;xsl:with-param name=&quot;dts&quot; select=&quot;$dts&quot;/&gt;
        &lt;xsl:with-param name=&quot;dds&quot; select=&quot;$dds|$nodes[1]&quot;/&gt;
        &lt;xsl:with-param name=&quot;nodes&quot; select=&quot;$nodes[position()&gt;1]&quot;/&gt;
      &lt;/xsl:call-template&gt;
    &lt;/xsl:when&gt;
    
    &lt;xsl:when test=&quot;name($nodes[1])=&apos;dt&apos;&quot;&gt;
      &lt;!-- Process the elements stocked in dts, dds. --&gt;
      &lt;xsl:if test=&quot;count($dts)&gt;0 or count($dds)&gt;0&quot;&gt;
        &lt;fo:list-item  xsl:use-attribute-sets=&quot;list.item&quot;&gt;
          &lt;fo:list-item-label end-indent=&quot;label-end()&quot;&gt;
            &lt;xsl:apply-templates select=&quot;$dts&quot;/&gt;
          &lt;/fo:list-item-label&gt;
          &lt;fo:list-item-body start-indent=&quot;body-start()&quot;&gt;
            &lt;xsl:apply-templates select=&quot;$dds&quot;/&gt;
        &lt;/fo:list-item-body&gt;&lt;/fo:list-item&gt;
      &lt;/xsl:if&gt;
      &lt;!-- dt is stored in dts variable, call itself recursively.--&gt;
      &lt;xsl:call-template name=&quot;process.dl.list&quot;&gt;
        &lt;xsl:with-param name=&quot;dts&quot; select=&quot;$nodes[1]&quot;/&gt;
        &lt;xsl:with-param name=&quot;nodes&quot; select=&quot;$nodes[position()&gt;1]&quot;/&gt;
      &lt;/xsl:call-template&gt;
    &lt;/xsl:when&gt;

    &lt;xsl:otherwise&gt;
      &lt;!-- The children of dl must be only dt, dd. --&gt;
      &lt;!-- Unfortunately, xsl:message does not work in MSXML3. --&gt;
      &lt;xsl:message&gt;
        &lt;xsl:text&gt;
         The elements except dt,dd are specified as a child of dl element.
        &lt;/xsl:text&gt;
        &lt;xsl:value-of select=&quot;name($nodes[1])&quot;/&gt;
        &lt;xsl:text&gt;).&lt;/xsl:text&gt;
      &lt;/xsl:message&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;dt&quot;&gt;
  &lt;xsl:element name=&quot;fo:block&quot; use-attribute-sets=&quot;dt&quot;&gt;
    &lt;xsl:if test=&quot;../@mode=&apos;debug&apos;&quot;&gt;
      &lt;xsl:attribute name=&quot;border-color&quot;&gt;blue&lt;/xsl:attribute&gt;
      &lt;xsl:attribute name=&quot;border-style&quot;&gt;dashed&lt;/xsl:attribute&gt;
      &lt;xsl:attribute name=&quot;border-width&quot; &gt;thin&lt;/xsl:attribute&gt;
    &lt;/xsl:if&gt;
    &lt;xsl:apply-templates /&gt;
  &lt;/xsl:element&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;dd&quot;&gt;
  &lt;xsl:choose&gt;
    &lt;xsl:when test=&quot;../@type=&apos;list&apos;&quot;&gt;
      &lt;xsl:element name=&quot;fo:block&quot; use-attribute-sets=&quot;dd.list&quot;&gt;
        &lt;xsl:if test=&quot;../@mode=&apos;debug&apos;&quot;&gt;
          &lt;xsl:attribute name=&quot;border-color&quot;&gt;red&lt;/xsl:attribute&gt;
          &lt;xsl:attribute name=&quot;border-style&quot;&gt;solid&lt;/xsl:attribute&gt;
          &lt;xsl:attribute name=&quot;border-width&quot; &gt;thin&lt;/xsl:attribute&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:apply-templates /&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;xsl:element name=&quot;fo:block&quot; use-attribute-sets=&quot;dd.block&quot;&gt;
        &lt;xsl:if test=&quot;../@mode=&apos;debug&apos;&quot;&gt;
          &lt;xsl:attribute name=&quot;border-color&quot;&gt;red&lt;/xsl:attribute&gt;
          &lt;xsl:attribute name=&quot;border-style&quot;&gt;solid&lt;/xsl:attribute&gt;
          &lt;xsl:attribute name=&quot;border-width&quot; &gt;thin&lt;/xsl:attribute&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:apply-templates /&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt;
</program>
<p>In this stylesheet, you have to determine which transformation to use from the following type by the type attribute defined for the dl element:
</p><ul><li>
list type: the label (dt) and the body(dd) are lined in horizontal way as fo:list-block.
</li><li>HTML type: the label (dt) and the body (dd) are lined in vertical way.
</li></ul><p type="continue">When &quot;list&quot; is specified in the type attribute, select the first one.
</p><p>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:
</p><ol><li>
The process.dl.list template take descendant elements of dl, start processing from the first element.
</li><li>
After getting dt, dd, store each of them to the dts, dds variable in appearing order.
</li><li>
When getting the next dt, take out dt, dd that are stored to dts, dls. Output fo:list-item and its descendants. Initialize the dts, dds, and store the dt to dts variable.
</li><li>
The above two processes are repeated until all the dt, dd are taken out.
</li><li>It is the end of the process when all the dt, dd under dl, are processed. If there are still dt, dd left in the dts, dds variable, take out these and output fo:list-item and its descendants.
</li></ol>
<p>
The following shows how this 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 figure shows the contents of XML source document described later.
</p><figure src="deflist-procen.emf"><title>Transforming the definition list into the list type. 

</title></figure>
<p>The process.dl.list template calls itself recursively. In the general programing language, it is natural to assign a value to a valiable and  process using a valiable. But in XSLT, it is impossible to assign a value to a variable, but it is possible to initiarize a value instead. Loops are formed by taking recursive process.
</p>
<p>
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 apearing order. 
</p>

</subsubsection>

<subsubsection><title>Example of a definition list
</title>
<p>
The following is a sample source data
</p>
<program><title>
A sample data of the definition list

</title>&lt;dl&gt;  
  &lt;dt&gt;Type of lists&lt;/dt&gt;
    &lt;dd&gt;There are three kinds of lists, that is unordered list, ordered list, and definition list.
    &lt;dl class=&quot;list&quot;&gt;
      &lt;dt&gt;From here&lt;/dt&gt;
      &lt;dd&gt;These are nested lists&lt;/dd&gt;
      &lt;dd&gt;The dd that does not match dt．&lt;/dd&gt;
      &lt;dt&gt;The dt without the dd&lt;/dt&gt;
      &lt;dt&gt;unordered list&lt;/dt&gt;
      &lt;dd&gt;Unordered lists are classified as square, circle and so on, according to the characters for label of line．&lt;/dd&gt; 
      &lt;dt&gt;Ordered lists&lt;/dt&gt;
      &lt;dd&gt;Ordered lists have various kinds of types according to the label format.&lt;/dd&gt;
    &lt;/dl&gt;
  &lt;/dd&gt;
  &lt;dt&gt;The elements that construct the table&lt;/dt&gt;
  &lt;dd&gt;fo:The table consists of table-caption, fo-table-caption, fo:table, fo:table-column, fo:table-head, fo:table-foot, fo:table-body, fo:table-row, fo:table-cell&lt;/dd&gt;
  &lt;dt&gt;kinds of color&lt;/dt&gt;
  &lt;dd&gt;16 kinds of colors can be used, such as red, blue, white, black and so on. Also it is possible to specify colors by RGB() functions.&lt;/dd&gt;
&lt;/dl&gt;</program>
<p>The following is the output of list type transformation. To make it look better, fo:list-item-labeland fo:list-item-body are bordered.
</p>
<div class="fo">
<fo:list-block provisional-distance-between-starts="3cm" provisional-label-separation="0.5cm">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">
type of list
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block space-before="0.3em" space-after="0.5em" border-color="red" border-style="solid" border-width="thin">
There are three kinds of lists, that is unordered list, ordered list, and definition list.
<fo:list-block provisional-distance-between-starts="3cm" provisional-label-separation="0.2cm">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">
From here
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block space-before="0.3em" space-after="0.5em" border-color="red" border-style="solid" border-width="thin">
These are listed nests.
</fo:block>
<fo:block space-before="0.3em" space-after="0.5em" border-color="red" border-style="solid" border-width="thin">
The dd that the dd does not match dt.
</fo:block>
</fo:list-item-body></fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">
The dt without the dd.
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
</fo:list-item-body></fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">Unordered lists
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block space-before="0.3em" space-after="0.5em" border-color="red" border-style="solid" border-width="thin">
Unordered lists are classified as square, circle and so on, according to the characters for label of line．
</fo:block>
</fo:list-item-body></fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">
Ordered lists
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block space-before="0.3em" space-after="0.5em" border-color="red" border-style="solid" border-width="thin">Ordered lists have various kinds of types according to the label format.
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</fo:list-item-body></fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">
The elements that construct the table
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block space-before="0.3em" space-after="0.5em" border-color="red" border-style="solid" border-width="thin">The table consists of fo:table-caption, fo-table-caption, fo:table, fo:table-column, fo:table-head, fo:table-foot, fo:table-body, fo:table-row, fo:table-cell.
</fo:block>
</fo:list-item-body></fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">
type of color
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block space-before="0.3em" space-after="0.5em" border-color="red" border-style="solid" border-width="thin">
16 kinds of colors can be used, such as red, blue, white, black and so on. Also it is possible to specify colors by RGB() functions
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</div><p>
The following is the output of HTML type transormation.
</p>
<div class="fo">
<fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">type of list
</fo:block>
  <fo:block space-before="0.3em" space-after="0.5em" start-indent="inherit + 4em" border-color="red" border-style="solid" border-width="thin">
There are three kinds of lists, that is unordered list, ordered list, and definition list.   
      <fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">From here</fo:block>
      <fo:block space-before="0.3em" space-after="0.5em" start-indent="inherit + 4em" border-color="red" border-style="solid" border-width="thin">These are nested lists</fo:block>
      <fo:block space-before="0.3em" space-after="0.5em" start-indent="inherit + 4em" border-color="red" border-style="solid" border-width="thin">The dd that the dt does not match dt.</fo:block>
      <fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">The dd without the dt.</fo:block>
      <fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">Unordered lists</fo:block>
      <fo:block space-before="0.3em" space-after="0.5em" start-indent="inherit + 4em" border-color="red" border-style="solid" border-width="thin">Unordered lists are classified as square, circle and so on, according to the characters for label of line．
</fo:block>
      <fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">Ordered lists</fo:block>
      <fo:block space-before="0.3em" space-after="0.5em" start-indent="inherit + 4em" border-color="red" border-style="solid" border-width="thin">
Ordered lists have various kinds of types according to the label format.
</fo:block>
    
  </fo:block>
  <fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">
The elements that construct the table
</fo:block>
  <fo:block space-before="0.3em" space-after="0.5em" start-indent="inherit + 4em" border-color="red" border-style="solid" border-width="thin">The table consists of fo:table-caption, fo-table-caption, fo:table, fo:table-column, fo:table-head, fo:table-foot, fo:table-body, fo:table-row, fo:table-cell.</fo:block>
  <fo:block font-weight="bold" border-color="blue" border-style="dashed" border-width="thin">
type of color
</fo:block>
  <fo:block space-before="0.3em" space-after="0.5em" start-indent="inherit + 4em" border-color="red" border-style="solid" border-width="thin">
16 kinds of colors can be used, such as red, blue, white, black and so on. Also it is possible to specify colors by RGB() functions.
</fo:block>
</div></subsubsection></subsection>

</section>
<section logo="XSLFormatter.bmp"><title>Appendix</title><p>The folowing are the books referring to XSL, XSLT.
</p>
<dl type="list" startdist="15em" gap="1em"><dt>XSLT Programmer&#x27;s Reference</dt><dd>Michael Kay / WROX<br/>This is a manual of XSLT. This book has rich contents. The second edition was issued in april, 2001.  
</dd><dt>PROFESSIONAL XSL</dt><dd>Kurt Cagle / WROX<br/>This is a manual of XSL in general. The contents have various fields, such as XSLT, XSL-FO, CSS, SVG. XSL Formatter, our products, is introduced in the chapter 9, CSS and XSL-FO using three pages.
</dd><dt>XSL Companion</dt><dd>Neil Bradley / Addison-Wesley<br/>
This book explains about XSLT, XSL-FO, HTML  briefly in general. XSL-FO is explained a lot, but it is somewhat old seen from the current recommendation. 

</dd><dt>PureSmartDoc
</dt>
<dd>For more information about PureSmartDoc, please refer to:
http://www.asahi-net.or.jp/~dp8t-asm/java/tools/</dd></dl>
<p>Antenna House Web site: http://www.antennahouse.com
</p>
<last-mark /></section></body>
</doc>
