XSL-FO:修订间差异
第42行: | 第42行: | ||
XSL-FO 的基本内容置标是从 CSS 及其层叠规则派生出来的,因此 XLS-FO 中的许多属性除非进行了显示重载否则就会延伸到子元素的部分。 |
XSL-FO 的基本内容置标是从 CSS 及其层叠规则派生出来的,因此 XLS-FO 中的许多属性除非进行了显示重载否则就会延伸到子元素的部分。 |
||
== |
==XSL-FO v1.0 的功能== |
||
XSL-FO 有许多处理文本布局的功能。除了上面介绍的一些之外,XSL-FO 语言可以完成下面定义的功能。 |
|||
XSL-FO is capable of a great deal of textual layout functionality. In addition to the information as specified above, XSL-FO's language allows for the specification of the following. |
|||
=== |
===多栏=== |
||
一个页面可能需要多栏的布局,在这种情况下,数据块按照顺序从一栏排到下一栏。单个的数据块可以扩展到所有栏,在页面中生成文本的分隔。分隔符上面的数据连在一起,下面的也连在一起,但是上面的不能与下面的连在一起。 |
|||
A page can be defined to have multiple columns. When this is the case, blocks flow from one column into the next by default. Individual blocks can be set to span all columns, creating a textual break in the page. The columns above this break will flow into each other, as will the columns below the break. But no text is allowed to flow from the above section to the below section. |
|||
根据 XSL-FO 页面规范的特性,每个页面可能会有不同的分栏及栏宽,因此文本可以很容易地从每页 3 栏转到每页 5 栏或者每页 1 栏。 |
|||
Because of the nature of XSL-FO's page specification, multiple pages may actually have different numbers and widths of columns. As such, text can flow from a 3 column page to a 5 column page to a 1 column page quite easily. |
|||
FO 的所有特性都能在多栏页面的约束下正常工作。 |
|||
All FO features work within the restrictions of a multi-column page. |
|||
=== |
===列表=== |
||
An XSL-FO list is, essentially, two sets of blocks stacked side by side. An entry consists of a block on the "left", or start inline direction, and a block sequence on the "right", or end inline direction. The block on the left is conceptually what would be the number or bullet in a list. However, it could just as easily be a string of text, as one might see in a glossary entry. The block on the right works as expected. Both of these blocks can be block containers, or have multiple blocks in a single list entry. |
An XSL-FO list is, essentially, two sets of blocks stacked side by side. An entry consists of a block on the "left", or start inline direction, and a block sequence on the "right", or end inline direction. The block on the left is conceptually what would be the number or bullet in a list. However, it could just as easily be a string of text, as one might see in a glossary entry. The block on the right works as expected. Both of these blocks can be block containers, or have multiple blocks in a single list entry. |
2007年1月18日 (四) 01:15的版本
模板参数错误!(代码36)
|
XSL-FO 是 XSL Formatting Objects 的缩写,它是一种用于文档格式的 XML 置标语言。XLS-FO 是XSL 的一部分,而 XLS 是一组定义 XML 数据转换与格式的 W3C 技术。XSL 的其它部分有 XSLT 与 XPath。截止到2006年12月12日,XSL-FO 的最新版本是 v1.1。
XSL-FO 基础
与其它的 HTML 与 CSS 组合不同,XSL-FO 是一种 unified 表示语言,它没有 HTML 中那样的置标语法格式,并且与 CSS 更改外部 XML 或者 HMTL 文档的缺省表示不同,XSL-FO 将所有的文档数据保存在内部。
XSL-FO 总的设计思想用户写到文档中的数据是 XML 语言的文档,而不是 FO,所用语言可以是 XHTML、DocBook 以及 TEI 或者其它任何的 XML 语言。然后,用户自己写一个或者找一个 XSLT 变换,将 XML 转换成 XSL-FO。
一旦生成了 XSL-FO 文档,就将它送到 FO 处理器这样的应用程序中。FO 处理器将 XSL-FO 文档转换成可以阅读或者可以打印的格式。最常见的 XSL-FO 输出格式是 PDF 或者 PostScript,有一些 FO 处理器只能输出成 RTF 这样的格式或者只能输出到图形用户界面的页面序列及内容。
人们最初认为 XSLT 语言本身仅仅是为这个目的所用的,但是现在由于更加通用的 XML 转换的出现已经超出了这个范围。由于这个转换是一个必然的过程,因此人们也常常将 XML 转换为 XSL-FO 的 XSLT 当作 XSL-FO 文档本身。甚至是 XSL-FO 的教程也在 FO 处理用法也用 XSLT 命令表示。
XSLT 转换过程功能非常强大,它可以自动生成内容的列表、参考链接、索引以及其它的结果。
XSL-FO 文档与 PDF 或者 PostScript 文档不同,它没有充分地描述文本在不同页面上的布局,相反,它仅仅描述了页面外观以及不同内容放置的位置。根据这些,FO 处理器依据 FO 文档中描述的边界确定文本的位置。XSL-FO 规范甚至允许不同的 FO 处理器根据所生成的页面有不同的响应。
例如,有些 FO 处理器为了节约空间在换行的时候会加入连字符,有些却不会这样做。不同的处理器甚至会使用不同的连字符算法,从一些简单的算法到需要考虑前后行是否也许要连字符这样复杂的算法。这样就会在不同的页面改变页面布局,尤其是带有边框的时候更是这样。另外还有一些场合,XSL-FO 规范明确允许 FO 处理器根据布局作出一定的选择。
虽然不同的 FO 处理器生成的结果并不一致,但是人们并不太关心。这是因为 XSL-FO 的目的是生成经过分页的可打印媒体。XSL-FO 文档本身通常用于中介的媒体,通常用于生成 PDF 文件或者作为最终要分发的打印文档。这与 HTML 直接作为最终形式分发给用户有所不同。因此,如果需要生成一个打印文档,只需要选择满足需要的 FO 处理器,比如布局效果以及较少的空白等,而无需在不同的处理器上测试 XSL-FO 文档。
XSL-FO 语言的概念
XSL-FO 语言的设计目的是用于分页媒体,采用的方式是类似于用于非分页媒体的 HTML 以及 CSS。因此,页面是 XSL-FO 结构内在的一个概念,FO 赋予了用户很大的权利以确定如何在页面上显示信息。
FO 最适合用在“内容驱动”设计的场合,这是图书、文章、法律文档等排版所用的标准方法。这涉及到一行邻近的文本以及嵌入在页面边界中的不同变化信息。这与报纸与杂志中所用的“布局驱动”设计有所不同。在那些文档中,如果无法在特定的位置完整地放进去,那么就会对内容进行裁减。XLS-FO 很难处理杂志布局的严格要求,实际上在很多场合,它根本不具备表示所需布局的能力。
尽管这种语言有这些设计局限,但是它仍然能够胜任很多的表现任务。它提供表格、列表、side floats 等许多特性。这些特性与 CSS 的布局特性类似,但是其中一些特性需要用 XSLT 表示。
XSL-FO 文档结构
XSL-FO 文档是 XML 文档,但是不必遵循 DTD 或其模型规范。相反,它们遵循 XSL-FO 规范中定义的语法。
XSL-FO 文档包括两个必须部分。第一部分列出页面布局的细节,第二部分是带有置标的文档数据,根据不同的页面布局确定如何在不同的页面上摆放内容。
页面布局定义了页面的属性。可以定义文本的排列方向以满足不同语言的要求,定义页面的尺寸以及页面边界。更加重要的特点是,它可以定义页面的顺序从而允许偶数页与奇数页的布局不同。例如,用于打印的文档可以定义更大的边界;在需要装订的时候可以留出更大的边界。
文档数据部分是一系列的数据流组成的,每个数据流都附属于一个页面布局。数据流包括一系列的按顺序排列的数据块,每个部分一系列的文本数据、内嵌的置标元素或者是二者的组合。在文档边界上也可以加入页码、章节等类似内容。
数据块以及内嵌元素的功能非常类似于 CSS,但是空白的填补与保留在 FO 与 CSS 之间有所不同。相对于页面方向的数据块及内嵌元素排列方向可以进行充分的定义,这样 FO 文档可以处理与英文排列方向不同的其它语言。FO 规范的语言与 CSS 2.1 不同,使用开始与结束这样的呈方向中性的术语而不是左与右来表示方向。
XSL-FO 的基本内容置标是从 CSS 及其层叠规则派生出来的,因此 XLS-FO 中的许多属性除非进行了显示重载否则就会延伸到子元素的部分。
XSL-FO v1.0 的功能
XSL-FO 有许多处理文本布局的功能。除了上面介绍的一些之外,XSL-FO 语言可以完成下面定义的功能。
多栏
一个页面可能需要多栏的布局,在这种情况下,数据块按照顺序从一栏排到下一栏。单个的数据块可以扩展到所有栏,在页面中生成文本的分隔。分隔符上面的数据连在一起,下面的也连在一起,但是上面的不能与下面的连在一起。
根据 XSL-FO 页面规范的特性,每个页面可能会有不同的分栏及栏宽,因此文本可以很容易地从每页 3 栏转到每页 5 栏或者每页 1 栏。
FO 的所有特性都能在多栏页面的约束下正常工作。
列表
An XSL-FO list is, essentially, two sets of blocks stacked side by side. An entry consists of a block on the "left", or start inline direction, and a block sequence on the "right", or end inline direction. The block on the left is conceptually what would be the number or bullet in a list. However, it could just as easily be a string of text, as one might see in a glossary entry. The block on the right works as expected. Both of these blocks can be block containers, or have multiple blocks in a single list entry.
Numbering of XSL-FO lists, when they are numbered, is expected to be done by the XSLT, or whatever other process, that generated the XSL-FO document. As such, number lists are to be explicitly numbered in XSL-FO.
Pagination Controls
The user can specify Widow and Orphan for blocks or for the flow itself, and allow the attributes to cascade into child blocks. Additionally, blocks can be specified to be kept together on a single page. For example, an image block and the description of that image can be set to never be separated. The FO processor will do its best to adhere to these commands, even if it requires creating a great deal of empty space on a page.
Footnotes
The user can create footnotes that appear at the bottom of a page. The footnote is written, in the FO document, in the regular flow of text at the point where it is referenced. The reference is represented as an inline definition, though it is not required. The body is one or more blocks that are placed by the FO processor to the bottom of the page. The FO processor guarantees that wherever the reference is, the footnote cited by that reference will appear on the same page. This will be so even if it means creating extra empty space on a page.
Tables
A FO table functions much like an HTML/CSS table. The user specifies rows of data for each individual cell. The user can, also, specify some styling information for each column, such as background color. Additionally, the user can specify the first row as a table header row, with its own separate styling information.
The FO processor can be told exactly how much space to give each column, or it can be told to auto-fit the text in the table.
Text Orientation Controls
FO has extensive controls for orienting blocks of text. One can, in the middle of a page, designate a block of text to be oriented in a different orientation. These oriented blocks can be used for languages in a different orientation from the rest of the document, or simply if one needs to orient the text for layout purposes. These blocks can contain virtually any kind of content, from tables to lists or even other blocks of reoriented text.
Miscellaneous
- Page number citations. A page that contains a special tag can be cited in text, and the FO processor will fill in the actual page number where this tag appears.
- Block borders, in a number of styles.
- Background colors and images.
- Font controls and weighting, as in CSS.
- Side floats.
- Miscellaneous Inline Elements
Capabilities of XSL-FO v1.1
Version 1.1 of XSL-FO adds a number of new features to version 1.0.
Multiple Flows and Flow Mapping
XSL-FO 1.0 was fairly restrictive about what text was allowed to go in what areas of a page. Version 1.1 loosens these restrictions significantly, allowing flowing text to be mapped into multiple explicit regions on a page. This allows for more newspaper-like typesetting.
Bookmarks
Many output formats for XSL-FO processors, specifically PDF, have bookmarking features. These allow the format to specify a string of text in a separate window that can be selected by the user. When selected, the document window scrolls immediately to a specific region of the document.
XSL-FO v1.1 now provides the ability to create named bookmarks in XSL-FO, thus allowing the processor to pass this on to an output format that supports it.
Indexing
XSL-FO 1.1 has features that support the generation of an index that might be found at the back of a book. This is done through referencing of properly marked-up elements in the FO document.
Last Page Citation
The last page can be generated without providing an explicit in-document reference to a specific anchor in the FO document. The definition of "last page" can be restricted to within a specific set of pages or to cover the entire document.
Advantages of XSL-FO
Because it is an XML language, only an XSLT transform (and an XSLT processor) are required to generate XSL-FO code from any XML language. One can easily write a document in TEI or DocBook, and transform it into HTML for web viewing or PDF (through a FO processor) for printing. In fact, there are many pre-existing TEI and DocBook XSLTs for both of these purposes.
Also, because it is an XML language, and specifically because it is without an explicit schema or DTD, it can store any kind of XML data. The most popular extra data would be SVG images, which a number of FO processors can read and add into the finished result.
Another advantage of XSL-FO is the relative ease of use. Much of the functionality of the language is based on work from CSS, so a CSS user will be familiar with the basics of the markup attributes. Understanding what a specific section of a FO document will look like is usually quite easy. This is compared to layout and typesetting packages like TeX, which are generally considered arcane.
Drawbacks of XSL-FO
The principal drawback of FO is the lack of support. FO processors are not easy to come by, and virtually none of them offer 100% compatibility with the formal specification. This despite the fact that the specification has been in existence for years. This is, in general, brought about by a lack of demand for XSL-FO. TeX and its like have long held the position as being a typesetting language, and most users of TeX see little need to switch to XSL-FO.
A less important disadvantage of XSL-FO is the fact that its ability to put content into the margins is not all that it could be. The ability to control such data is, while functional, not nearly as complete as one might prefer.
Another problem with FO is that, while it is easy to understand, it is difficult and incredibly verbose to write by hand. XSLT was designed to make writing XSL-FO documents easy, so there was no impetus in the language for making the FO documents themselves be more concise. The problem that this creates is that a neophyte must learn not only the details of writing FO documents, but how to write an XSLT transform as well. That is, of course, only a valid concern if one is not using a pre-existing XSLT transform written for one of the standard document formats.
参见
外部链接
- XSL-FO 1.0 Specification
- XSL-FO 1.1 Specification
- What is XSL-FO? on XML.com
- Apache FOP Open source and royalty free implementation of XSL-FO
- W3 Schools A good source for beginners and dabblers
- FO examples and techniques Excellent reference site setup by Dave Pawson, for those who want to use FOP, but were afraid to ask.
- XSL-FO: Ready for Prime Time? on the Gilbane Report
- XSL-FO Tutorial and Samples on Antenna House
- Data2Type (German) XSL-FO information
- XSL Formatting Objects Tutorial on RenderX
- XSL-FO Tutorial and Samples on Ecrion.com