最新消息:20210917 已从crifan.com换到crifan.org

【已解决】给docbook所输出的pdf中的revhistory历史版本的表格,添加边框

Docbook crifan 1847浏览 0评论

【问题】

已经可以成功用docbook生成pdf中,包含revhistory所对应的历史版本部分的内容了,但是所显示出来的表格,没有边框,效果如下:

修订历史 表格 无边框

现在希望输出的pdf中,该修订历史部分的表格,是有边框的,就像之前用word生成出来的效果一样:

之前的word生成的表格 有边框

【解决过程】

1.找到了这个官网的解释: Formatting revhistory – Chapter 29. Revision control,参考其解释,照葫芦画瓢,想要把示例代码:

<xsl:attribute-set name="revhistory.title.properties">
  <xsl:attribute name="font-size">12pt</xsl:attribute>
  <xsl:attribute name="font-weight">bold</xsl:attribute>
  <xsl:attribute name="text-align">center</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="revhistory.table.properties">
  <xsl:attribute name="border">0.5pt solid black</xsl:attribute>
  <xsl:attribute name="background-color">#EEEEEE</xsl:attribute>
  <xsl:attribute name="width">50%</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="revhistory.table.cell.properties">
  <xsl:attribute name="border">0.5pt solid black</xsl:attribute>
  <xsl:attribute name="font-size">9pt</xsl:attribute>
  <xsl:attribute name="padding">4pt</xsl:attribute>
</xsl:attribute-set>

添加到合适的地方去,但是找了半天,也不知道到底该加入到哪个文件里面。

不过后来找到titlepage.xsl中,有revhistory.title.properties,所以估计是这个文件。

然后想办法,复制了一份titlepage.xsl存为titlepage_crl.xsl,然后去把此文件添加到我的docbook所用的xls文件docbook_fo_crl_yahei.xsl:

<xsl:import href="titlepage_crl.xsl"/>

然后去修改对应的titlepage_crl.xsl,在最开始部分添加上面的代码。

并且也注意到了,其后面的有相关的内容:

        <fo:table-cell number-columns-spanned="3" xsl:use-attribute-sets="revhistory.table.cell.properties">
          <fo:block xsl:use-attribute-sets="revhistory.title.properties">
	    <xsl:choose>
	      <xsl:when test="d:title|d:info/d:title">
		<xsl:apply-templates select="d:title|d:info/d:title" mode="titlepage.mode"/>
	      </xsl:when>
	      <xsl:otherwise>
		<xsl:call-template name="gentext">
		  <xsl:with-param name="key" select="'RevHistory'"/>
		</xsl:call-template>
	      </xsl:otherwise>
	    </xsl:choose>
	  </fo:block>
        </fo:table-cell>

然后,重新使用xsltproc生成fo,再调用fop生成pdf,结果的确是有效的:

添加边框后的效果

剩下的,就是去修改配置,改成自己需要的效果了。

然后就是用了这样的配置:

<xsl:attribute-set name="revhistory.title.properties">
  <xsl:attribute name="font-size">12pt</xsl:attribute>
  <xsl:attribute name="font-family">
    <xsl:value-of select="$title.fontset"/>
  </xsl:attribute>
  <xsl:attribute name="text-align">left</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="revhistory.table.properties">
  <xsl:attribute name="border">0.5pt solid black</xsl:attribute>
  <xsl:attribute name="width">50%</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="revhistory.table.cell.properties">
  <xsl:attribute name="border">0.5pt solid black</xsl:attribute>
  <xsl:attribute name="font-size">9pt</xsl:attribute>
  <xsl:attribute name="padding">4pt</xsl:attribute>
</xsl:attribute-set>

生成出这样的效果:

修改成自己需要的效果

【总结】

想要对于revhistory部分,去配置输出pdf时的效果,是到对应的fo文件夹下面,给titlepage.xsl增加xsl:attribute-set部分的配置,即可。

 

【后记】

刚才无意间发现,上述方法有点问题。

其会使得输入的二级标题的索引表号丢失掉,变成了这种:

显示异常的二级标题

而正常的是这样的:

正常显示的二级标题

因为我的命令行是带参数去开启二级标题section的索引编号的:

xsltproc.exe --stringparam section.autolabel 1 --stringparam section.label.includes.component.label 1 --stringparam bibliography.numbered 1 --xinclude -o /cygdrive/e/Dev_Root/docbook/dev/src/docbook/books/VBR/output/fo/MPEG_VBR.fo /usr/share/sgml/docbook/xsl-ns-stylesheets/fo/docbook_fo_crl_yahei.xsl /cygdrive/e/Dev_Root/docbook/dev/src/docbook/books/VBR/src/MPEG_VBR.xml

对于上述问题,经过尝试,这样可以规避该问题:

在docbook_fo_crl_yahei.xsl中,

取消import该xsl,而手动添加上述的对于revhistory的配置的内容,变成这样:

<!--<xsl:import href="titlepage_crl.xsl"/> -->

<xsl:attribute-set name="revhistory.title.properties">
  <xsl:attribute name="font-size">12pt</xsl:attribute>
  <xsl:attribute name="font-family">
    <xsl:value-of select="$title.fontset"/>
  </xsl:attribute>
  <xsl:attribute name="text-align">left</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="revhistory.table.properties">
  <xsl:attribute name="border">0.5pt solid black</xsl:attribute>
  <xsl:attribute name="width">50%</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="revhistory.table.cell.properties">
  <xsl:attribute name="border">0.5pt solid black</xsl:attribute>
  <xsl:attribute name="font-size">9pt</xsl:attribute>
  <xsl:attribute name="padding">4pt</xsl:attribute>
</xsl:attribute-set>


这样,就既可以实现给revhistory的表格添加边框,又可以避免丢失section的索引标号了。

【后记 2012-06-05】

后来才看到,原来官网的Formatting revhistory已经解释了上述相关的配置了。

所以,有时间的话,还是多看看官网的文档,还是很有价值的。

转载请注明:在路上 » 【已解决】给docbook所输出的pdf中的revhistory历史版本的表格,添加边框

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.189 seconds, using 23.30MB memory