【问题】
已经可以成功用docbook生成pdf中,包含revhistory所对应的历史版本部分的内容了,但是所显示出来的表格,没有边框,效果如下:
现在希望输出的pdf中,该修订历史部分的表格,是有边框的,就像之前用word生成出来的效果一样:
【解决过程】
1.找到了这个官网的解释: Formatting revhistory – Chapter 29. Revision control,参考其解释,照葫芦画瓢,想要把示例代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | < 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,在最开始部分添加上面的代码。
并且也注意到了,其后面的有相关的内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | < 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,结果的确是有效的:
剩下的,就是去修改配置,改成自己需要的效果了。
然后就是用了这样的配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | < 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的索引编号的:
1 | 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的配置的内容,变成这样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <!--<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已经解释了上述相关的配置了。
所以,有时间的话,还是多看看官网的文档,还是很有价值的。