XSL-FO教程[转]

XSL-FO教程

通过本章的学习你将了解到什么是XSL-FO。
应该如何使用XSL-FO来格式化你的XML文档输出

内容目录

XSL-FO 介绍
An introduction to XSL-FO. What it is and what it can do.
XSL-FO概述,知道它的用途是什么

XSL-FO 文档
This chapter describes the structure of XSL-FO documents.
这章会描述XSL-FO文档的结构

XSL-FO Areas
This chapter describes the area model of XSL-FO.
描述XSL-FO的区域模型

XSL-FO Output
This chapter describes the "Output Elements" of XSL-FO documents.
XSL-FO文档里的"输出元素"

XSL-FO Flow
This chapter describes the "Output Flow" of XSL-FO documents.
XSL-FO文档里的"输出流"

XSL-FO Pages
This chapter describes how XSL-FO defines page layout.
怎样使用XSL-FO来定义页面的布局

XSL-FO Blocks
This chapter describes XSL-FO output blocks.
XSL-FO输出块

XSL-FO 列表
This chapter describes how XSL-FO defines lists.
怎样使用XSL-FO定义列表

XSL-FO 表格
This chapter describes how XSL-FO defines tables.
怎样使用XSL-FO定义表格

XSL-FO 和 XSLT
This chapter describes how XSL-FO uses XSLT.
XSL-FO是如何使用XSLT的

XSL-FO 软件
This chapter describes our favorite XSL-FO software.
比较流行的XSL-FO软件

XSL-FO 对象参考
The full list of XSL-FO objects and their properties.
有关XSL-FO对象和其他的一些属性


XSL-FO 介绍
w3pop.com / 2006-09-19

XSL-FO 文档

XSL-FO is about formatting XML data for output.
XSL-FO将用于输出的XML数据格式化


What You Should Already Know
你应该已经知道的知识

Before you study XSL-FO you should have a basic understanding of XML and XML Namespaces.
在学习XSL-FO之前你应该对XML和XML名称空间有基本的了解

If you want to study these subjects first, please read our XML Tutorial.
如果你想先学习这些,请阅读我们的.XML 教程.


What is XSL-FO?
什么是XSL-FO?

  • XSL-FO is a language for formatting XML data
    XSL-FO是用语格式化XML数据的语言
  • XSL-FO stands for Extensible Stylesheet Language Formatting Objects
    XSL-FO全称为Extensible Stylesheet Language Formatting Objects (格式化对象的可扩展样式表语言)
  • XSL-FO is a W3C Recommendation
    XSL-FO是W3C参考标准
  • XSL-FO is now formally named XSL
    XSL-FO现在通常叫做XSL

XSL-FO is About Formatting
XSL-FO用于格式化

XSL-FO is an XML-based markup language describing the formatting of XML data for output to screen, paper or other media.
XSL是一种以XML为基础的标记语言,它对输出到屏幕、纸张或其它媒体上的XML数据的格式化作了具体的描述。


XSL-FO is Formally Named XSL
XSL-FO现在通常叫做XSL

Why this confusion? Is XSL-FO and XSL the same thing?
XSL-FO和 XSL是相同的东西吗?为什么会这样的混淆?

Yes it is, but we will give you an explanation:
的确是这样,可以给出这样的解释:

Styling is both about transforming and formatting information. When the World Wide Web Consortium (W3C) made their first XSL Working Draft, it contained the language syntax for both transforming and formatting XML documents.
样式化包括信息的转换格式化。当万维网联盟(W3C)做出第一份XSL工作草案时,它囊括了XML文档的转换和格式化的语法。

Later, the XSL Working Group at W3C split the original draft into separate Recommendations:
后来,W3C的XSL工作组把原草案分成了以下几块参考标准:

  • XSLT, a language for transforming XML documents
    XSLT,用于转换XML文档的语言
  • XSL or XSL-FO, a language for formatting XML documents
    XSL 或 XSL-FO,用于格式化XML文档的一种语言
  • XPath, a language for navigating through elements and attributes in XML documents
    XPath,用于在XML文档中对元素和属性进行操作的语言

The rest of this tutorial is about formatting XML documents: XSL-FO, also called XSL.
指南剩下部分是关于格式化XML文档的:XSL-FO,也称作XSL

You can read more about XSLT in our XSLT Tutorial.
在我们的XSLT 教程中你可以了解更多关于XSLT 

You can read more about XPath in our XPath Tutorial.
在我们的XPath 教程中你可以了解更多关于 XPath.


XSL-FO is a Web Standard
XSL-FO是网络标准

XSL-FO became a W3C Recommendation 15. October 2001. Formally named XSL.
2001年10月15日,XSL-FO已经成为了W3C的参考标准。它通常被称作XSL。

To read more about the XSL activities at W3C please read our W3C Tutorial.
在我们的W3C 教程.你可以读到更多关于XSL的特性

XSL-FO 文档
w3pop.com / 2006-09-20

XSL-FO 介绍 XSL-FO 区域
XSL-FO documents are XML files with output information.
XSL-FO文档是含有输出信息的XML文件

XSL-FO Documents
XSL-FO文档

XSL-FO documents are XML files with output information. They contain information about the output layout and output contents.
XSL-FO文档是含有输出信息的XML文件。它们包含了输出排版和输出内容的信息

XSL-FO documents are stored in files with a .fo or a .fob file extension. It is also quite common to see XSL-FO documents stored with an .xml extension, because this makes them more accessible to XML editors.
XSL-FO文档以扩展名a .fo 或 a .fob的文件保存在文件里。XSL-FO文档以an .xml扩展名来保存也非常常见。因为这样使它们能更容易地被XML编辑器访问。


XSL-FO Document Structure
XSL-FO文档结构

XSL-FO documents have a structure like this:
XSL-FO文档结构就像这样:

<?xml version="1.0" encoding="ISO-8859-1"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>
<fo:simple-page-master master-name="A4">
<!-- Page template goes here -->
</fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="A4">
<!-- Page content goes here -->
</fo:page-sequence>
</fo:root>

Structure explained
结构解析

XSL-FO documents are XML documents, and must always start with an XML declaration:
XSL-FO文档是XML文档,所以必须在开始有一个XML声明:

<?xml version="1.0" encoding="ISO-8859-1"?>

The <fo:root> element is the root element of XSL-FO documents. The root element also declares the namespace for XSL-FO:
<fo:root>元素是XSL-FO文档的根元素。根元素也给XSL-FO命名了名称空间(namespaces):

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<!-- The full XSL-FO document goes here -->
</fo:root>

The <fo:layout-master-set> element contains one or more page templates:
<fo:layout-master-set>元素包含着一个或多个页面模板

<fo:layout-master-set>
<!-- All page templates go here -->
</fo:layout-master-set>

Each <fo:simple-page-master> element contains a single page template. Each template must have a unique name (master-name):
每个<fo:simple-page-master>元素包含着一个单独的页面模板。每个模板都有一个特殊的名称(“master-name“)

<fo:simple-page-master master-name="A4">
<!-- One page template goes here -->
</fo:simple-page-master>

One or more <fo:page-sequence> elements describe the page contents. The master-reference attribute refers to the simple-page-master template with the same name:
一个或多个<fo:page-sequence>元素描述了页面内容。Master-reference属性指的是同名的“简单页面控制(simple-page-master)模板”。

<fo:page-sequence master-reference="A4">
<!-- Page content goes here -->

</fo:page-sequence>

Note: The master-reference "A4" does not actually describe a predefined page format. It is just a name. You can use any name like "MyPage", "MyTemplate", etc.
注意: master-reference "A4"并不是真正地描述了预先定义的页面格式。它只是个名称。你可以起像"MyPage", "MyTemplate",等等的名称。

XSL-FO 区域
w3pop.com / 2006-09-20

XSL-FO 文档 XSL-FO 输出

XSL-FO uses rectangular boxes (areas) to display output.
XSL-FO用矩形块(域)显示结果


XSL-FO Areas
XSL-FO区域

The XSL formatting model defines a number of rectangular areas (boxes) to display output.
XSL格式化模型定义了大量的矩形域(块状区)来显示数据

All output (text, pictures, etc.) will be formatted into these boxes and then displayed or printed to a target media.
所有的结果(文本,图片,等等)都会被格式化后放入这些区域里,然后在目标媒体上显示或打印出来。

We will take a closer look at the following areas:
让我们进一步看看下面的区域:

  • Pages 页面
  • Regions 区域
  • Block areas 块区域
  • Line areas 行区域
  • Inline areas 行内区域

XSL-FO Pages
XSL-FO Pages[页面]

XSL-FO output is formatted into pages. Printed output will normally go into many separate pages. Browser output will often go into one long page.
XSL-FO结果被格式化成页面形式。打印出来的结果通常会形成很多分开的页面。浏览器的输出的结果通常会是长长的一页。

XSL-FO Pages contain Regions.
XSL-FO页面包含区域


XSL-FO Regions
XSL-FO Regions

Each XSL-FO Page contains a number of Regions:
XSL-FO每页都含有大量的区域

  • region-body (the body of the page)
    region-body (the body of the page) 区域 — 主体(页面的主体)
  • region-before (the header of the page)
    region-before (the header of the page) 区域—前体(页面标题)
  • region-after (the footer of the page)
    region-after (the footer of the page) 区域-后体(页面的页脚)
  • region-start (the left sidebar)
    region-start (the left sidebar) 区域—开头(左工具条)
  • region-end (the right sidebar)
    region-end (the right sidebar) 区域—末尾(右工具条)

XSL-FO Regions contain Block areas.
XSL-FO区域含有块状区域


XSL-FO Block Areas
XSL-FO Block Areas[块状区域]

XSL-FO Block areas define small block elements (the ones that normally starts with a new line) like paragraphs, tables and lists.
XSL-FO块状区域定义了小的块状元素(以新一行开头的元素),例如图表、表格和列表

XSL-FO Block areas can contain other Block areas, but most often they contain Line areas.
XSL-FO块状区域包含其他的块状区域,但它们常包含行区域。


XSL-FO Line Areas
XSL-FO Line Areas[行区域]

XSL-FO Line areas define text lines inside Block areas.
XSL-FO行区域定义了块状区域里的文本行。

XSL-FO Line areas contain Inline areas.
XSL-FO行区域包行内区域


XSL-FO Inline Areas
XSL-FO Inline Areas[行区域]

XSL-FO Inline areas define text inside Lines (bullets, single character, graphics, and more).
XSL-FO定义了行里(“用于强调段落”的粗体圆点,单字符,图形,等等)的文本

XSL-FO 输出
w3pop.com / 2006-09-20

XSL-FO 区域 XSL-FO Flow

XSL-FO defines output inside <fo:flow> elements.
XSL-FO在<fo:flow>元素里定义输出结果


XSL-FO Page, Flow, and Block
XSL-FO 页面、流向、区域

"Blocks" of content "Flows" into "Pages" and then to the output media.
"Flows"元素的内容"Blocks"进入"Pages",然后到达输出的媒体。

XSL-FO output is normally nested inside <fo:block> elements, nested inside <fo:flow> elements, nested inside <fo:page-sequence> elements:
XSL-FO输出通常嵌在<fo:block>元素、<fo:flow>元素、以及<fo:page-sequence>元素里:

<fo:page-sequence>
<fo:flow flow-name="xsl-region-body">
<fo:block>
<!-- Output goes here -->
</fo:block>
</fo:flow>

</fo:page-sequence>


XSL-FO Example
XSL-FO例子

It is time to look at a real XSL-FO example:
是时候来看看XSL-FO的实例了

<?xml version="1.0" encoding="ISO-8859-1"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>

<fo:simple-page-master master-name="A4">
</fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">

<fo:block>Hello w3pop.com</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>

The output from this code would be something like this:
这份代码应输出如下结果:

Hello w3pop.com

 

 

 

 

 

 

 

 

 


XSL-FO Flow
w3pop.com / 2006-09-20

XSL-FO 输出 XSL-FO 页面

XSL-FO pages are filled with data from <fo:flow> elements.
XSL-FO充满了来自<fo:flow>元素的数据


XSL-FO Page Sequences
XSL-FO 页面排序

XSL-FO uses <fo:page-sequence> elements to define output pages.
XSL-FO 用<fo:page-sequence>元素来定义输出页面

Each output page refers to a page master which defines the layout.
每个输出的页面都涉及到定义页面排版的页面模版。

Each output page has a <fo:flow> element defining the output.
每页输出页面指都有定义输出的<fo:flow>元素

Each output page is printed (or displayed) in sequence.
每页输出页面都按顺序打印(或显示)


XSL-FO Flow

XSL-FO pages are filled with content from the <fo:flow> element.
XSL-FO页面有很多来自<fo:flow>元素的内容

The <fo:flow> element contains all the elements to be printed to the page.
<fo:flow>元素包含了要被打印在页面上的所有元素

When the page is full, the same page master will be used over (and over) again until all the text is printed.
当页面印满时,相同的页面模版(page master)会被反复地使用直到所有文本都被打印出来为止。


Where To Flow?
“流向”哪里?

The <fo:flow> element has a "flow-name" attribute.
<fo:flow>元素有"flow-name"(流向名)属性

The value of the flow-name attribute defines where the content of the <fo:flow> element will go.
流向名(flow-name)属性的值决定了<fo:flow>元素内容的流向。

The legal values are:
合法值有:

  • xsl-region-body (into the region-body)
    xsl-region-body (into the region-body)流向区域主体
  • xsl-region-before (into the region-before)
    xsl-region-before (into the region-before)流向区域前端
  • xsl-region-after (into the region-after)
    xsl-region-after (into the region-after)流向区域后端
  • xsl-region-start (into the region-start)
    xsl-region-start (into the region-start)流向区域端
  • xsl-region-end (into the region-end)
    xsl-region-end (into the region-end)流向区域末端

XSL-FO 页面
w3pop.com / 2006-09-20

XSL-FO Flow XSL-FO 块状区域

XSL-FO uses page templates called "Page Masters" to define the layout of  pages.
XSL-FO使用名为“Page Masters”的页面模板来定义页面的排版。


XSL-FO Page Templates
XSL-FO页面模板

XSL-FO uses page templates called "Page Masters" to define the layout of  pages. Each template must have a unique name:
XSL-FO使用称作“Page Masters”的页面模板来定义页面的排版。每块模板必须有个独立的名称

<fo:simple-page-master master-name="intro">

<fo:region-body margin="5in" />
</fo:simple-page-master>
<fo:simple-page-master master-name="left">
<fo:region-body margin-left="2in" margin-right="3in" />

</fo:simple-page-master>
<fo:simple-page-master master-name="right">
<fo:region-body margin-left="3in" margin-right="2in" />
</fo:simple-page-master>

In the example above, three <fo:simple-page-master> elements, define three different templates. Each template (page-master) has a different name.
在上面的例子里,三个<fo:simple-page-master>元素,定义了三块不同的模板。每块模板都有不同的名称

The first template is called "intro". It could be used as a template for introduction pages.
第一块模板称作“intro”,它可以用于介绍页面的模板

The second and third templates are called "left" and "right". They could be used as templates for even and odd page numbers.
第二和第三块模板称作"left" and "right"。它们可用于定义奇数页面和偶数页面


XSL-FO Page Size
XSL-FO页面大小

XSL-FO uses the following attributes to define the size of a page:
XSL-FO使用下面的属性来定义页面的大小

  • page-width defines the width of a page
    page-width定义页面的宽度
  • page-height defines the height of a page
    page-height定义页面的高度

XSL-FO Page Margins
XSL-FO页面页边空白(margin)

XSL-FO uses the following attributes to define the margins of a page:
XSL-FO用下面属性来定义页边空白

  • margin-top defines the top margin
    margin-top定义了顶边空白
  • margin-bottom defines the bottom margin
    margin-bottom定义了底边空白
  • margin-left defines the left margin
    margin-left定义了左边空白
  • margin-right defines the right margin
    margin-right定义了右边空白
  • margin defines all four margins
    margin定义了所有的四边空白

XSL-FO Page Regions
XSL-FO页面区域

XSL-FO uses the following elements to define the regions of a page:
XSL-FO用以下元素来定义页面的区域

  • region-body defines the body region
    region-body定义了整体区域
  • region-before defines the top region (header)
    region-before定义了顶端的区域(标题)
  • region-after defines the bottom region (footer)
    region-after定义了底端区域(页脚)
  • region-start defines the left region (left sidebar)
    region-start定义了左端区域(左端工具条)
  • region-end defines the right region (right sidebar)
    region-end定义了右端区域(右端工具条)

Note that the region-before, region-after, region-start, and region-end is a part of the body region. To avoid text in the body region to overwrite text in these regions, the body region must have margins at least the size of these regions.
要注意前端区域(region-before),后端区域(region-after),始端区域(region-start),末端区域(region-end)是主体区域的一部分,主体区域的空白尺寸至少要和这些区域一样

Margin Top

M
a
r
g
i
n

L
e
f
t
 

REGION BEFORE
R
E
G
I
O
N

S
T
A
R
T

 

 

 

 

 

REGION BODY

 

 

 

 

 

 

R
E
G
I
O
N

E
N
D

REGION AFTER
M
a
r
g
i
n

R
i
g
h
t
Margin Bottom


XSL-FO Example
XSL-FO例子

This is an extract from an XSL-FO document:
这是一份XSL-FO文档的部分

<fo:simple-page-master master-name="A4"
page-width="297mm" page-height="210mm"

margin-top="1cm" margin-bottom="1cm"
margin-left="1cm" margin-right="1cm">
<fo:region-body margin="3cm"/>

<fo:region-before extent="2cm"/>
<fo:region-after extent="2cm"/>
<fo:region-start extent="2cm"/>
<fo:region-end extent="2cm"/>

</fo:simple-page-master>

The code above defines a "Simple Page Master Template" with the name "A4".
上面的代码定义了名称为"A4"的"Simple Page Master Template"

The width of the page is 297 millimeters and the height is 210 millimeters.
这页宽297毫米,高210毫米

The top, bottom, left, and right margins of the page are all 1 centimeter.
页面的顶部和底部左右空白都是1厘米

The body has a 3 centimeter margin (on all sides).
主体部分有3厘米宽的空白(在所有边上)

The before, after, start, and end regions (of the body) are all 2 centimeters.
主体的前后始末部分都是2厘米

The width of the body in the example above can be calculated by subtracting the left and right margins and the region-body margins from the width of the page itself:
在这个例子当中,主体宽度可以这样计算:页面自身宽度减去左右空白和区域主体空白的宽度,具体如下:

297mm - (2 x 1cm) - (2 x 3cm) = 297mm - 20mm - 60mm = 217mm.

Note that the regions (region-start and region-end) are not a part of the calculation. As described earlier, these regions are parts of the body.
要注意区域(始区域和末区域)并不在计算范围之内。像前面所说的那样,这些区域只是主体的一部分。

XSL-FO 块状区域
w3pop.com / 2006-09-20

XSL-FO 页面 XSL-FO 列表
XSL-FO output goes into blocks.
XSL-FO输出进入块状区域。

XSL-FO Pages, Flow, and Block
XSL-FO Pages, Flow, 以及 Block

"Blocks" of content "Flow" into "Pages" of the output media.
"Flows"的内容("Blocks")进入了输出媒体的页面"Pages"。

XSL-FO output is normally nested inside <fo:block> elements,  nested inside <fo:flow> elements, nested inside <fo:page-sequence> elements:
XSL-FO输出通常被嵌在<fo:block>元素,<fo:flow>元素,<fo:page-sequence>元素内

<fo:page-sequence>
<fo:flow flow-name="xsl-region-body">
<fo:block>
<!-- Output goes here -->
</fo:block>

</fo:flow>
</fo:page-sequence>


Block Area Attributes
Block Area 属性

Blocks are sequences of output in rectangular boxes:
块状区域是一组在矩形框内的输出的结果:

<fo:block
border-width="1mm">
This block of output will have a one millimeter border around it.
</fo:block>

Since block areas are rectangular boxes, they share many common area properties:
因为块状区域的是矩形框,它们共享很多共同的区域性质:
  • space before and space after最上和最下空间
  • margin页边
  • border边框
  • padding填充
space before
margin
border
padding



content






space after

The space before and space after is the empty space separating the block from the other blocks.
“Space before”和“space after”空间是用来分隔本区域和别的区域的。

The margin is the empty area on the outside of the block.
页边(margin)是块状区域外面的空白区域

The border is the rectangle drawn around the external edge of the area. It can have different widths on all four sides. It can also be filled with different colors and background images.
边界(border)是矩形框的四条边;它们可以有不同的宽度;它们也可以填充不同的颜色和背景图片

The padding is the area between the border and the content area.
填充是位于边界和内容区域之间的地方

The content area contains the actual content like text, pictures, graphics, or whatever.
内容区域包含了诸如文本、图片、图表等实际存在的内容。


Block Margin
块状区域的页边(margin)

  • margin四边留白
  • margin-top顶部留白
  • margin-bottom底部留白
  • margin-left左留白
  • margin-right右留白

Block Border
块状区域边界

Border style attributes:
边界样式属性:

  • border-style边界类型
  • border-before-style边界前端类型
  • border-after-style边界后端类型
  • border-start-style边界开始类型
  • border-end-style边界结束类型
  • border-top-style (same as border-before)顶边类型(和 边界前端类型一样)
  • border-bottom-style (same as border-after)底边类型(边界后端类型一样)
  • border-left-style (same as border-start)左边类型(和边界始类型一样)
  • border-right-style (same as border-end)右边类型(和边界右端类型一样)

Border color attributes:
边界的颜色属性:

  • border-color边界颜色
  • border-before-color前边界色
  • border-after-color后边界色
  • border-start-color始端边界色
  • border-end-color末端边界色
  • border-top-color (same as border-before)顶端边界色(和前边界色相同)
  • border-bottom-color (same as border-after)底端边界色(和后边界色相同)
  • border-left-color (same as border-start)左边界色(和始端边界色相同)
  • border-right-color (same as border-end)右边界色(和末端边界色相同)

Border width attributes:
边界宽度属性:

  • border-width边宽
  • border-before-width边界前宽
  • border-after-width边界后宽
  • border-start-width边界始宽
  • border-end-width边界末宽
  • border-top-width (same as border-before)顶边宽度(和边界前宽相同)
  • border-bottom-width (same as border-after)底边宽度(和边界后宽相同)
  • border-left-width (same as border-start)左边宽度(和边界始宽相同)
  • border-right-width (same as border-end)右边宽度(和边界右宽相同)

Block Padding
块状区域填充

  • padding填充
  • padding-before前填充
  • padding-after后填充
  • padding-start始填充
  • padding-end末填充
  • padding-top (same as padding-before)顶填充(和始填充一样)
  • padding-bottom (same as padding-after)底填充(和后填充一样)
  • padding-left (same as padding-start)左填充(和始填充一样)
  • padding-right (same as padding-end)右填充(和末填充一样)

Block Background
块状区域背景

  • background-color背景颜色
  • background-image背景图形
  • background-repeat背景反复
  • background-attachment (scroll or fixed)背景附件(滚动或固定)

Block Styling Attributes
块状区域样式属性

Blocks are sequences of output that can be styled individually:
块状区域是可以分别单独称呼的输出的排列

<fo:block
font-size="12pt"

font-family="sans-serif">
This block of output will be written in a 12pt sans-serif font.
</fo:block>

Font attributes:
字体属性:

  • font-family字体样式
  • font-weight字体粗细
  • font-style字体式样
  • font-size字体大小
  • font-variant字体变量

Text attributes:
文本属性:

  • text-align文本排列
  • text-align-last文本排列持续
  • text-indent文本缩进
  • start-indent起始缩进
  • end-indent末尾缩进
  • wrap-option (defines word wrap)隐藏选项(定义文字隐藏)
  • break-before (defines page breaks)页面前端断开(定义页面断开)
  • break-after (defines page breaks)页面后端断开(定义页面断开)
  • reference-orientation (defines text rotation in 90" increments)参考量定位(定义在90度内的文本旋转) 

Example
举例

<fo:block
font-size="14pt" font-family="verdana" color="red"
space-before="5mm" space-after="5mm">

W3Schools
</fo:block>
<fo:block
text-indent="5mm"
font-family="verdana" font-size="12pt"
space-before="5mm" space-after="5mm">

At w3pop.com you will find all the Web-building tutorials you
need, from basic HTML and XHTML to advanced XML, XSL, Multimedia
and WAP.
</fo:block>

Result:
结果


W3Schools

   At w3pop.com you will find all the Web-building tutorials you need, from basic HTML and XHTML to advanced XML, XSL, Multimedia and WAP.
 

When you look at the example above, you can see that it will take a lot of code to produce a document with many headers and paragraphs.
从上面的例子,你可以看到要制造一份有很多标题和段落的文档要用上大量的代码

Normally XSL-FO document do not combine formatting information and content like we have done here.
一般来说XSL-FO文档不象我们这样把格式化信息和内容结合起来。

With a little help from XSLT we can put the formatting information into templates and write a cleaner content.
在XSLT的一些帮助下,我们可以把格式化信息放到模板里,这样的内容就更清爽单一了

You will learn more about how to combine XSL-FO with XSLT templates in a later chapter in this tutorial.
在这指南的后面几章里你可以知道更多关于怎样把XSL-FO和XSLT模本相结合。

XSL-FO 列表
w3pop.com / 2006-09-20

XSL-FO 块状区域 XSL-FO 表格

XSL-FO uses List Blocks to define lists.
XSL-FO用列表块区定义列表


XSL-FO List Blocks
XSL-FO列表区

There are four XSL-FO objects used to create lists:
用于创建列表的XSL-FO对象有以下四个:

  • fo:list-block (含有整个列表)
  • fo:list-item (含有列表里的每一项)
  • fo:list-item-label (含有列表项的标签,典型的例子如:一个<fo:block>元素含有一个数字,字符,等等.)
  • fo:list-item-body (含有列表项的内容和主体,典型的例子如:一个或多个<fo:block>对象)

An XSL-FO list example:
一份XSL-FO列表的例子:

<fo:list-block>
<fo:list-item>
<fo:list-item-label>
<fo:block>*</fo:block>

</fo:list-item-label>
<fo:list-item-body>
<fo:block>Volvo</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item>

<fo:list-item-label>
<fo:block>*</fo:block>
</fo:list-item-label>
<fo:list-item-body>
<fo:block>Saab</fo:block>

</fo:list-item-body>
</fo:list-item>
</fo:list-block>

The output from this code would be:
这份代码应该输出如下结果:


 * Volvo
 * Saab
 

XSL-FO 表格
w3pop.com / 2006-09-20

XSL-FO 列表 XSL-FO 和 XSLT
XSL-FO uses the <fo:table-and-caption> element to define tables.
XSL-FO用<fo:table-and-caption>元素定义表格

XSL-FO Tables
XSL-FO表格

The XSL-FO table model is not very different from the HTML table model.
XSL-FO的表格模式和HTML表格模式相差不大。

There are nine XSL-FO objects used to create tables:
有9个XSL-FO对象可以用于创建表格:

  • fo:table-and-caption
  • fo:table
  • fo:table-caption
  • fo:table-column
  • fo:table-header
  • fo:table-footer
  • fo:table-body
  • fo:table-row
  • fo:table-cell

XSL-FO uses the <fo:table-and-caption> element to define a table. It contains a <fo:table> and an optional <fo:caption> element.
XSL-FO用<fo:table-and-caption>元素定义表格。它包含一个<fo:table>元素和一个可选择的<fo:caption>元素

The <fo:table> element contains optional <fo:table-column> elements, an optional <fo:table-header> element, a <fo:table-body> element, and an optional <fo:table-footer> element. Each of these elements has one or more <fo:table-row> elements, with one or more <fo:table-cell> elements:
<fo:table>元素包含几个可选择的<fo:table-column>元素,一个可选择的<fo:table-footer>元素。这些元素都有一个或多个的<fo:table-row>元素,和一个或多个的<fo:table-cell>元素

<fo:table-and-caption>
<fo:table>

<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>

<fo:table-header>
<fo:table-row>
<fo:table-cell>

<fo:block font-weight="bold">Car</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold">Price</fo:block>

</fo:table-cell>
</fo:table-row>
</fo:table-header>

<fo:table-body>
<fo:table-row>
<fo:table-cell>

<fo:block>Volvo</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>$50000</fo:block>
</fo:table-cell>

</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>SAAB</fo:block>
</fo:table-cell>

<fo:table-cell>
<fo:block>$48000</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>

</fo:table>
</fo:table-and-caption>

The output from this code would something like this:
这段代码将输出如下结果:

Car Price
Volvo $50000
SAAB $48000

XSL-FO 和 XSLT
w3pop.com / 2006-09-20

XSL-FO 表格 XSL-FO 软件

XSL-FO and XSLT can help each other.
XSL-FO 和 XSLT可以“互相帮助”


Remember this Example?
还记得这个例子吗?

<fo:block
font-size="14pt" font-family="verdana" color="red"
space-before="5mm" space-after="5mm">

W3pop
</fo:block>
<fo:block
text-indent="5mm"
font-family="verdana" font-size="12pt"
space-before="5mm" space-after="5mm">

At w3pop.com you will find all the Web-building tutorials you
need, from basic HTML and XHTML to advanced XML, XSL, Multimedia
and WAP.
</fo:block>

Result:
结果


W3pop

   At w3pop.com you will find all the Web-building tutorials you need, from basic HTML and XHTML to advanced XML, XSL, Multimedia and WAP.
 

The example above is from the chapter about XSL-FO Blocks.
上面的例子来自于XSL-FO Blocks.的相关章节


With a Little Help from XSLT
从XSLT中得到一些帮助

Remove the XSL-FO information from the document:
从文档清除XSL-FO信息的方法:

<header>
W3pop
</header>
<paragraph>
At W3pop.com you will find all the Web-building tutorials you
need, from basic HTML and XHTML to advanced XML, XSL, Multimedia
and WAP.
</paragraph>

Add an XSLT transformation:
添加一条XSLT信息的方法:

<xsl:template match="header">
<fo:block
font-size="14pt" font-family="verdana" color="red"

space-before="5mm" space-after="5mm">
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="paragraph">

<fo:block
text-indent="5mm"
font-family="verdana" font-size="12pt"
space-before="5mm" space-after="5mm">

<xsl:apply-templates/>
</fo:block>
</xsl:template>

And the result will be the same:
结果仍然相同:


W3pop

   At W3pop.com you will find all the Web-building tutorials you need, from basic HTML and XHTML to advanced XML, XSL, Multimedia and WAP.
 


XSL-FO 软件
w3pop.com / 2006-09-20

XSL-FO 和 XSLT XSL-FO 参考资料

XSL-FO needs formatting software to produce output.
XSL-FO需要格式化软件来输出结果。


XSL-FO Processors
XSL-FO处理器

An XSL-FO processor is a software program for formatting XSL documents for output.
XSL-FO处理器是用来格式化XML文档输出的软件程序。

Most XSL-FO processors can output PDF documents and quality print, as well as HTML and other formats.
大多数XSL-FO处理器可以输出PDF文档,并进行高质量的打印,当然还可输出HTML等其他形式的文件。

Some well-known XSL-FO processors are described below.
下面介绍的是一些知名的XSL-FO处理器


XSL Formatter
XSL Formatter

XSL Formatter is a software to format XML documents for production-quality printing and output to PDF.
XSL Formatter是一种用来格式化XML文档的软件,从而可以对PDF文件进行高质量的打印输出。

Antenna House has been providing version V2 of the same product since January, 2002 in the global market, and XSL Formatter was rated as one of the best quality product at the XML 2002, XML 2003 conferences held in Europe.
曾经自2002年一月在全球市场上推出了相同产品的V2版。在欧洲举办的XML 2002, XML 2003峰会上,XSL Formatter被认同是品质最佳的产品。

Building on over 4 years of experience developing XSL-FO software, Antenna House has completely written from scratch an entirely new Formatter that offers significant enhancements and provides a solid foundation on which to continue to move forward.
在开发XSL-FO软件拥有4年经验的基础之上,, Antenna House又从头开始开发全新的Formatter,这种Formatter将增加一些更显著的功能,并为将来的继续发展提供了坚实的基础。

Visit Antenna House
访问 Antenna House


Xinc Beta Release
Xinc Beta的发行

Xinc is an XSL-FO processor by Lunasil LTD.
Xinc是Lunasil公司出品的的XSL-FO处理器

Xinc is designed to be fast, multithreaded and memory efficient. A Swing based XSL-FO viewer allows you to view and print XSL-FO files as well as generate PDF files with the click of a button. Xinc can be used as a server component via its Java API. Xinc can also be used in a Microsoft server environment by using its COM interface. New features include hyphenation, basic-link, PDF output, memory/speed optimizations and a simple COM interface.
Xinc的特点是运行快速,多路处理,并有记忆效果。有摆动装置的XSL-FO阅读器可以让你浏览和打印XSL-FO文件,并且只要点击鼠标就可以操纵PDF文件。通过Xinc的Java API(Java应用程序接口),Xinc可作为服务器组件。通过Xinc的COM(串行通讯端口)分界面,它也可在Microsoft服务器环境下使用。它的新特特点有:连字符号连接,基础连接,PDF输出,内存/速度最优化和简单的COM界面。

Visit Lunasil Ltd
访问Lunasil Ltd


Scriptura

Inventive Designers Scriptura is a cross-platform document design and generation solution based on XSLT and XSL-FO.
Scriptura是在XSLT 和 XSL-FO 基础上的交互式平台文档设计器和问题处理器。

Scriptura has a WYSIWYG design tool and engine. The XSL-FO formatter used in the engine is no longer based on Apache FOP, but is written from scratch by Inventive Designers. The new features in this release are: support for bulleted and numbered lists, 'break-before' and 'break-after' properties, extended bar code options and improved number and currency formatting. A free trial version is available for download.
Scriptura拥有WYSIWYG(即见及所得)工具和引擎。在引擎中用到的格式转换器已经不是以Apache FOP为基础的,而是设计者们重新开始做。这个版本中的新特点是:支持圆点和编号列表,break-before' 和'break-after' 特性;扩展的条形码选项、改进的数字、货币格式。免费的体验版本可以下载得到。

Visit Inventive Designers
访问Inventive Designers

XSL-FO 参考资料
w3pop.com / 2006-09-20

XSL-FO 软件

XSL Formatting Objects Reference
XSL格式化对象参考资料

The process that converts a description into a presentation is called formatting.
把具体描述转化为表达式的过程称为格式化:

Object
对象
Description
描述
basic-link Represents the start resource of a link
开始资源(start resource)连接
bidi-override Overrides the default Unicode BIDI direction
拒绝默认统一字符编码标准BIDI的用法
block Defines a block of output (e.g. paragraphs and titles)
定义输出组件(比如:段落、标题)
block-container Defines a block-level reference-area
定义一个block等级参考面
character Specifies a character that will be mapped to a glyph for presentation
指定表达字形的字符(这个字符将被映射到一个字形中来表达)
color-profile Defines a color-profile for a stylesheet
定义样式表的颜色轮廓
conditional-page-master-reference Specifies a page-master to be used when the conditions defined are true
指定当条件为true真时,可以使用page-master
declarations Groups global declarations for a stylesheet
生命一个通用的样式
external-graphic Used for a graphic where the graphics data resides outside of the XML result tree
用于图解(图形数据位于XML结果树的外部)
float Typically used to position an image in a separate area at the beginning of a page OR to position an image to one side, with the content flowing along-side of the image
用于在开始页面的单独区域里指定一个图形,或者将图形放置在一边(内容浮于图形的周围)
flow Contains all elements to be printed to a page
包含所有要打印在页面上的元素
footnote Defines a footnote within the region-body of a page
在页面区域主体定义脚注
footnote-body Defines the content of the footnote
定义脚注内容
initial-property-set Formats the first line of an <fo:block>
格式<fo:block>第一行
inline Formats a part of a text with a background or enclosing it in a border
通过背景属性或将其嵌入一个边框来定义一部分文本的格式
inline-container Defines an inline reference-area
定义行内(inline)参数区域
instream-foreign-object Used for inline graphics or for "generic" objects where the object's data resides as descendants of <fo:instream-foreign-object>
用于inline制图或对象数据以<fo:instream-foreign-object>子元素形式"存在的generic"对象
layout-master-set Holds all masters used in a document
在文档中使用所有的master
leader Used to generate "." to separate titles from page numbers in table of contents, or to create input fields in forms, or to create horizontal rules
通过产生“.”来给页面中的标题进行排版,或者建立一个表格输入区或一个平行法则
list-block Defines a list
定义列表
list-item Contains each item in the list
包含列表的每个项
list-item-body Contains the content/body of the list-item
包含列表项的内容/主体
list-item-label Contains the label for the list-item (typically a number, character, etc.)
包含列表项的标签(尤其市数字、字符等等)
marker Used with <fo:retrieve-marker> to create running headers or footers
通过<fo:retrieve-marker>来创建运行标题或页脚
multi-case Contains (within an <fo:multi-switch>) each alternative sub-tree of XSL-FO objects. The parent <fo:multi-switch> will choose which alternative to show and hide the rest
(在<fo:multi-switch>中)包含XSL-FO对象的每个可供选择的子树(sub-tree)。父级<fo:multi-switch>会选择其中一个来决定是显示还是隐藏余下的部分。
multi-properties Used to switch between two or more property-sets
用来转换2个或更多的性质设置
multi-property-set Specifies an alternative property-set that will be applied depending on the state of the user agent
根据用户代理状态,指定一个应用性质设置
multi-switch Holds one or more <fo:multi-case> objects and controls the switching between them (activated by <fo:multi-toggle>)
解释一个或多个<fo:multi-case>对象,控制它们(受<fo:multi-toggle>触发)之间的转换
multi-toggle Used to switch to another <fo:multi-case>
用于转换成另一<fo:multi-toggle>
page-number Represents the current page-number
表现为当前页码
page-number-citation References the page-number for the page that contains the first normal area returned by the cited object
给页面定页码,而此页面是包含被引用对象返回的第一标准区域
page-sequence A container for page output elements. There will be one <fo:page-sequence> object for each page layout
页面输出元素的容器。这儿有一个页面专用的<fo:page-sequence>对象
page-sequence-master Specifies which simple-page-masters are to be used and in which order
指定使用哪个simple-page-masters以及以何种顺序使用
region-after Defines a page footer
定义页脚
region-before Defines a page header
定义页眉
region-body Defines a page body
定义页面主体
region-end Defines the right sidebar of a page
定义页面右工具条
region-start Defines the left sidebar of a page
定义页面左工具条
repeatable-page-master-alternatives Specifies repetition of a set of simple-page-masters
指定一组simple-page-masters循环
repeatable-page-master-reference Specifies repetition of a single simple-page-master
指定单个simple-page-masters循环
retrieve-marker Used with <fo:marker> to create running headers or footers
通过<fo:marker>创建运行标题与页脚
root The root (top) node for XSL-FO documents
XSL-FO文件的根(top)节点
simple-page-master Defines the size and shape of a page
定义页面的尺寸与形状
single-page-master-reference Specifies a page-master to be used at a given point in the sequence of pages
定义page-master用于有顺序页面中的给出的要点
static-content Contains static content (e.g. headers and footers) that will be repeated on many pages
包含了在许多页面中都重复的静态内容(如:标题与页脚)
table Formats the tabular material of a table
格式表格的列表材料
table-and-caption Formats a table and its caption
格式表格及其标题
table-body Container for table rows and table cells
表格行和表格单元的容器
table-caption Contains the caption for a table
包含表格标题
table-cell Defines a table cell
定义表格单元
table-column Formats the columns of a table
格式表格栏
table-footer Defines a table footer
定义表格页脚
table-header Defines a table header
定义表格标题
table-row Defines a table row
定义表格行
title Defines a title for a page-sequence
定义页面次序的标题
wrapper Specifies inherited properties for a group of XSL-FO objects
指定XSL-FO对象组的遗传道具
posted @ 2006-11-17 16:12  疯一样的自由  阅读(1926)  评论(0编辑  收藏  举报