新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   >>中国XML论坛<<     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → [原创]XSL-FO 学习笔记 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 11284 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: [原创]XSL-FO 学习笔记 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     fanzhixin 帅哥哟,离线,有人找我吗?巨蟹座1980-7-3
      
      
      等级:大二(研究C++)
      文章:33
      积分:230
      门派:XML.ORG.CN
      注册:2005/4/28

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给fanzhixin发送一个短消息 把fanzhixin加入好友 查看fanzhixin的个人资料 搜索fanzhixin在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看fanzhixin的博客楼主
    发贴心情 [原创]XSL-FO 学习笔记

    先来看一段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>

    下面来解释一下个部分的含义:
    1,因为 xsl-fo 文件本身是 xml 文档,所以开头必须有 xml 声明:
    <?xml version="1.0" encoding="ISO-8859-1"?>

    2,<fo:foot> 标签是 FO 的根标签,所有内容必须包含这个标签内,并且同时声明命名空间<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

    3,<fo:layout-master-set> 装载文档模板

    4,<fo:simple-page-master> 装载单页模板,每个模板必须有唯一的名字,例:
    <fo:simple-page-master master-name="A4">


    5,<fo:page-sequence> 转载文档的内容,它的属性 master-reference 来指定输出样式与上面<fo:simple-page-master> 模板的 master-name 属性相对应,例:
    <fo:page-sequence master-reference="A4">

    注:
        master-reference 和 master-name 的属性不是预设的,你可以任意取值。


    FO 将打印页面分成若干矩形盒(areas)来表达显示输出:
       矩形盒包括
           
      Pages > Regions > Block > (Block)Line > Inline

    ">" 代表包括关系

    1,Pages

         Pages 控制页面样式,因为打印时文档要分成好几页,浏览时是一大长页,所以页面样式有Pages 控制,

      2,Regions

        Regions 包括以下属性

    region-body (the body of the page) (文本内容)
    region-before (the header of the page) (表头)
    region-after (the footer of the page) (页角)
    region-start (the left sidebar) (左边界)
    region-end (the right sidebar) (右边届)
    3,Block

        Block 包含一些小的元素,比如段落,表格,列表==

    4,Line

        定义文本行

    5,Inline

      定义文本行中的文字(如 bullets, 单个文字, 图片==)

    Pages 内的嵌套规则

      <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>
    Pages 中的内容是由<fo:flow>元素组成的

    XSL-fo 通过 <fo:page-sequence> 来定义输出页

    每个输出页以 master 属性来定义输出样式

    每个输出页都有<fo:flow>定义输出内容

    每个输出页都在一个 sequence 中

    <fo:flow> 包括一切需要打印在 page 内的内容

    如果一页填不下,相同的 page master 会用得到下一页,直到打印为止

    <fo:flow> 有 flow-name 属性,它的值决定内容的现实位置

    合法的值

    xsl-region-body (into the region-body) (文本内容)
    xsl-region-before (into the region-before) (表头)
    xsl-region-after (into the region-after) (页角)
    xsl-region-start (into the region-start) (左边界)
    xsl-region-end (into the region-end) (右边届)
    XSL-fo 的页面模板

       XSL-fo 用页面模板(“page-master”)来定义输出,每个模板都必须有唯一的名字。

        

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

    在以上的代码中有三个<fo:simple-page-master> 标签,定义了三个模板,每个模板(“pagemaster”)都有不同的名字。

    第一个用于介绍,第二个和第三个,用于奇数页和偶数页。

    模板(<fo:simple-page-master>)属性

       

    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

    页面大小

    page-width 定义页宽
    page-height 定义页高
    页边空白

          

    margin-top        定义上边空白
    margin-bottom   定义下边空白
    margin-left        定义左边空白
    margin-right      定义右边空白
    margin             定义所有四边空白

    页面区域标签

    <fo:region-body>       定义主体区域
    <fo:region-before>     顶一定不区域(页眉)
    <fo:region-after>       定义底部区域(页角)
    <fo:region-start>        定义左部区域(左选项条)
    <fo:region-end>         定义右部区域(优选项条)
    注:

       region-before, region-after, region-start, region-end 是 region-body 的一部分,为了防止 body 的内容溢出到这些部分,你必须设置 body 的 margin 最少是他们的大小。

      

      例子:

    <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>
    上面定义了一个名为 A4 的模板,宽297mm,高210mm, 四个页边空白未1mm,body 离页边的距离是3cm, 页的四边(页眉、页角、左边栏、右边栏)都为2cm

       可以计算 body 的大小,例

          body 宽=297mm-2*(30mm)-2*10mm=217mm

    Block 标签,直接装载内容

       文档内容 < Block < Flow < Page

    <fo:page-sequence>
      <fo:flow flow-name="xsl-region-body">
        <fo:block>
          <!-- Output goes here -->
        </fo:block>
      </fo:flow>
    </fo:page-sequence>
    Block 的属性
    space before

    margin
    border
    padding

    content


    space after

    Block 的 Area 属性

    space before and space after(Block 之间的距离)
    margin (Block 边缘的空白)
    border (Block 外部边框,可以设置大小和颜色)
    padding (内容和边框之间的填充)

    Block 的 Margin 属性

    margin
    margin-top
    margin-bottom
    margin-left
    margin-right
    Block 的 Border 属性

         

    Border 样式属性:

    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 颜色属性:

    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 宽度属性:

    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 (滚动或固定)
    * Block 内容样式 属性

       <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-family
    font-weight
    font-style
    font-size
    font-variant
    文字格式:

    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)
    例:

    <fo:block
        font-size="14pt" font-family="verdana" font-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 W3Schools you will find all the Web-building tutorials you
    need, from basic HTML and XHTML to advanced XML, XSL, Multimedia
    and WAP.
    </fo:block>
    你可以看到,生成简单的文档需要很很复杂的代码。
    一般 xsl-fo 文档不需要这么复杂的代码,我们可以通过 xslt 将格式化信息写入模板里,这样文档就会更整洁。
    稍后我们会学怎样组合 xsl-fo 和 xslt.
    XSL-FO 通过 List Blocks 来定义列表
    fo:list-block (包含整个列表)
    fo:list-item (包含每个项)
    fo:list-item-label (包括列表项的标签,比如数字、字符等等。)
    fo:list-item-body (包括列表的内容。比如 <fo:block> 对象。)
    例:

    <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>
    XSL-FO 通过 <fo:table-and-caption> 来定义表格
    XSL-FO 中的表格和 HTML 没太大的区别。
    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
    <fo:table-and-caption> 用来定义表格,它有 <fo:table> 和 <fo:caption> 两个元素

    <fo:table> 所包含的可选元素有<fo:table-column> 、<fo:table-header>、<fo:table-body>、<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>
    XSL-FO 和 XSLT 合作
    <xsl:template match="header">
    <fo:block
        font-size="14pt" font-family="verdana" font-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>
    XSK-FO 参考http://www.w3schools.com/xslfo/xslfo_reference.asp


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/8/24 11:20:00
     
     GoogleAdSense巨蟹座1980-7-3
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/27 16:41:17

    本主题贴数5,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  [原创]XSL-FO 学习笔记(10750字) - fanzhixin,2005年8月24日
        回复:  不错!(5字) - 907941727,2008年6月24日
        回复:  FOP要怎么安装呢?(17字) - solidluck,2008年1月26日
        回复:  很好呀,只是不知道怎么去执行这个XSL-FO呢(40字) - solidluck,2008年1月25日
        回复:  (2字) - sam,2005年8月24日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    82.031ms