当前位置:编程学习 > XML/UML >>

XSL对象格式使用指南(三)

答案:    
  
  在前两篇中我们已经讨论了怎样处理封面页和内容页,现在我们准备把以下内容放入这西班牙评论手册里。
  
  
  标题和段落属性由<fo:block> 元素控制,粗体和带下划线的词语由<fo:inline>元素控制。现在开始描述第一个标题:
  <fo:block
  
  font-size="14pt" font-family="sans-serif"
  font-weight="bold" color="green"
  space-before="6pt" space-after="6pt">
  Introduction
  
  <fo:block>
  
  
  
  space-before属性和space-after属性是储存区域中属性设置值中的两种。这些属性和层叠样式表CSS相类似
  字体属性
  font-family,font-weight,font-style (斜体),font-size,font-stretch,font-variant
  背景属性
  background-color,background-image,background-repeat,background-attachment (卷动或固定)
  边界属性
  border-location-info:
  location可以为before,after,start,,end,,top,bottom,left或right
  info is 可以为字体,宽度或颜色
  填充属性
  padding-location:`
  location is 可以为before,after,,start,end,top,bottom,left或right
  空白属性
  margin-location:
  location可以为top,bottom,left或right
  文本排列属性
  text-align和text-align-last (用作文本最后一行); 函数可以为start,end,left,right或center
  缩排属性
  text-indent (第一行),start-indent,end-indent
  其他属性
  wrap-option (没有约束或有约束);widows和orphans (决定页面的顶部或左部有多少行)break-after和break-before;reference-orientation (将正文旋转90度)
  
  通过这些属性,我们可以明确定位一个复杂的段落。定位使用 “复合数据类型”的标点符号可以使页面的版面可以在不同的图像分辨率下自动适应:
  <fo:block
  
  text-indent="1em"
  font-family="sans-serif" font-size="12pt"
  space-before.minimum="2pt"
  space-before.maximum="6pt"
  space-before.optimum="4pt"
  space-after.minimum="2pt"
  space-after.maximum="6pt"
  space-after.optimum="4pt">
  This handbook covers the major topics in Spanish, but is by no means complete.
  
  <fo:block>
  
  
  
  如果你的文档有很多标题或段落时,你不需要将所有的文档逐一格式化。有XSLT ,我们能用XSLT把文档写入HTML 或转换成详细的XSL:FO 译本。以下是已经转换好的HTML :
  <h3>Introduction</h3>
  <p>
  This handbook covers the major topics in Spanish, but is by no means complete.
  </p>
  <h3>Accents</h3>
  <p>
  When we pronounce English words, one syllable is usually
  emphasized (<b>stressed</b>, in linguistic terms).
  The stressed syllable is underlined in the following words: com<u>pu</u>ter,<u>lan</u>guage, de<u>vel</u>opment, suc<u>ceeds</u>. Spanish words also have a stressed syllable, and there are rules for determining which syllable carries the emphasis.
  </p>
  
  
  下边是标题和段落的模板:
  <xsl:template match="h3">
  
  <fo:block font-size="14pt" font-family="sans-serif"
  font-weight="bold" color="green"
  space-before="6pt" space-after="6pt">
  <xsl:apply-templates/>
  </fo:block>
  
  </xsl:template>
  
  <xsl:template match="p">
  
  <fo:block
  text-indent="1em"
  font-family="sans-serif" font-size="12pt"
  space-before.minimum="2pt"
  space-before.maximum="6pt"
  space-before.optimum="4pt"
  space-after.minimum="2pt"
  space-after.maximum="6pt"
  space-after.optimum="4pt">
  <xsl:apply-templates/>
  </fo:block>
  
  </xsl:template>
  
  
  
  在这篇文章初始化时已经设定了模板并将<html>和 <body>标记了,我们在这时不用再重复,只需用浏览器检查一下。
  这是文档的树结构。用<b> 和 <u> 标记了最后一个子接点。它们在行列中的句柄为<fo:inline>元素。
  <xsl:template match="b">
  
  <fo:inline font-weight="bold">
  <xsl:apply-templates/>
  </fo:inline>
  
  </xsl:template>
  
  <xsl:template match="u">
  
  <fo:inline text-decoration="underline">
  <xsl:apply-templates/>
  </fo:inline>
  
  </xsl:template>
  
  <xsl:template match="i">
  
  <fo:inline font-style="italic">
  <xsl:apply-templates/>
  </fo:inline>
  
  </xsl:template>
  
  
  
  当我们通过XSLT 和FOP建立HTML文件将得到:
  
  
  
  
  
  

上一个:XMLDOM对象方法:对象属性
下一个:XSL对象格式使用指南(四)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,