XSLT-FO基础知识

  1. .fo.fob.xml为后缀名。
  2. XSL-FO文档属于XML文档,以XML声明起始。
  3. 根元素:<fo:root> 根元素要声明XSL-FO的命名空间。
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <!-- 此处是 XSL-FO 文档的内容 -->
</fo:root>

含有一个或多个页面模板,即

<fo:layout-master-set>
  <--所有的页面模板-->
</fo:layout-master-set>

包含一个单一的页面模板。每个模板必须有唯一的名称master-name

<fo:simple-page-master master-name="1234">
 <!-- 一个页面模板-->
</fo:simple-page-master>

定义输出的页面。使用master-reference属性引用simple-page-master模板。master-reference属性值为要引用的simple-page-master的master-name的值。

区域

XSL-FO使用矩形框(区域)来显示输出
有5种区域:Pages(页面)、Regions(区)、Block areas(块区域)、Line areas(行区域)、Inline areas(行内区域)。所有的输出会被格式化到这些框中,然后输出到媒介。

将内容块输出到媒介。嵌套在<fo:page-sequence>中。包含所有被打印到页面的元素。

<fo:page-sequence>
 <fo:flow flow-name="xsl-region-body">
  <fo:block>
   ...
  </fo:block>
 </fo:flow>
</fo:page-sequence>

的属性flow-name定义元素的内容去往何处。
合法的值:

  • xsl-region-body(进入region-body)
  • xsl-region-before (进入 region-before)
  • xsl-region-after (进入 region-after)
  • xsl-region-start (进入 region-start)
  • xsl-region-end (进入 region-end)

可以定义很多属性,属性

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 W3School</fo:block>
  </fo:flow>
</fo:page-sequence>

</fo:root>

page-master

定义页面整体的布局,每个page-master都必须有唯一的master-name

的属性:
页面尺寸
page-widthpage-height
页面边距
margin-topmargin-rightmargin-bottommargin-leftmargin

列表

<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>

表格

<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>

猜你喜欢

转载自blog.csdn.net/e_li_na/article/details/79285018