最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】docbook为html,pdf添加页眉和页脚

Docbook crifan 5395浏览 0评论

【背景】

之前看到:

http://velocity.apache.org/docbook/DocBook-Framework-1.0.pdf

中的pdf有页眉和页脚:

docbook pdf header and footer

所以,想要也去给自己的pdf,以及html,去添加页眉和页脚。

其中我目前的pdf是这样的:

my docbook pdf header and footer

【折腾过程】

1.参考:

8.3. PDF headers and footers

和官网的:

pdf的:

Running headers and footers

和html的:

HTML headers and footers

去试试,

结果是:

最终是用:

E:\Dev_Root\docbook\dev\config\docbook-xsl-ns-1.78.1\fo\docbook_crl.xsl

中加上:

<!--============================================================================
header setting
=============================================================================-->

<!-- E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.78.1\fo\pagesetup.xsl -->

<xsl:template name="footer.content">
  <xsl:param name="pageclass" select="''"/>
  <xsl:param name="sequence" select="''"/>
  <xsl:param name="position" select="''"/>
  <xsl:param name="gentext-key" select="''"/>

<!--
  <fo:block>
    <xsl:value-of select="$pageclass"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="$sequence"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="$position"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="$gentext-key"/>
  </fo:block>
-->

  <fo:block>
    <!-- pageclass can be front, body, back -->
    <!-- sequence can be odd, even, first, blank -->
    <!-- position can be left, center, right -->
    <xsl:choose>
      <xsl:when test="$pageclass = 'titlepage'">
        <!-- nop; no footer on title pages -->
      </xsl:when>

      <xsl:when test="$double.sided != 0 and $sequence = 'even'
                      and $position='left'">
        <fo:page-number/>
      </xsl:when>

      <xsl:when test="$double.sided != 0 and ($sequence = 'odd' or $sequence = 'first')
                      and $position='right'">
        <fo:page-number/>
      </xsl:when>

      <xsl:when test="$double.sided = 0 and $position='right'">
        <fo:page-number/>
      </xsl:when>

      <xsl:when test="$position='center'">
        <xsl:value-of select="/book/info/title"/>
      </xsl:when>

      <xsl:when test="$sequence='blank'">
        <xsl:choose>
          <xsl:when test="$double.sided != 0 and $position = 'left'">
            <fo:page-number/>
          </xsl:when>
          <xsl:when test="$double.sided = 0 and $position = 'center'">
            <fo:page-number/>
          </xsl:when>
          <xsl:otherwise>
            <!-- nop -->
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>


      <xsl:otherwise>
        <!-- nop -->
      </xsl:otherwise>
    </xsl:choose>
  </fo:block>
</xsl:template>

只实现了:

让footnote部分,页号在右下角显示的。

 

目前的问题:

试过如下这些:

      <xsl:when test="$position='center'">
        <xsl:value-of select="ancestor-or-self::book/bookinfo/title"/>
      </xsl:when>

      <xsl:when test="$position='center'">
        <xsl:value-of select="ancestor-or-self::book/info/title"/>
      </xsl:when>

      <xsl:when test="$position='center'">
        <xsl:value-of select="ancestor-or-self::info/title"/>
      </xsl:when>

      <xsl:when test="$position='center'">
        <xsl:value-of select="ancestor-or-self::/book/info/title"/>
      </xsl:when>

      <xsl:when test="$position='center'">
        <xsl:value-of select="/book/info/title"/>
      </xsl:when>

都还是无法获得想要的book的title。

而对应的docbook的book的xml中,是正常的:

<book version="5.0"
    xmlns="http://docbook.org/ns/docbook"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    xmlns:xl="http://www.w3.org/1999/xlink"

    xml:lang="zh_CN"
    >
<info>
    <title>Docbook开发手记</title>
    <subtitle></subtitle>

但是就是无法获得。

感觉像是:

所谓的runtime的header和footer,是无法获得这些内容的。

 

但是,还是很奇怪,因为要是之前示例代码中的:

      <xsl:when test="$sequence = 'first' and $position = 'center'"> 
        <xsl:value-of 
               select="ancestor-or-self::book/bookinfo/corpauthor"/> 8 
      </xsl:when>

那么按理来说,我这里的:

book/info/title

就也该可以的才对。

 

注:

对于select的用法,已经参考了:

XPath Axes

了,确保写法是正确无误的。

2.最终,目前的效果如下:

my docbook footer page number right

即:

footer部分的,页号在右边;

但是footer中间部分,想要显示book的info的title,暂时未成功;

header的中间,还是保留之前的chapter的title。

暂时所用配置如下:

<!--============================================================================
header setting
=============================================================================-->

<!-- E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.78.1\fo\pagesetup.xsl -->

<xsl:template name="footer.content">
  <xsl:param name="pageclass" select="''"/>
  <xsl:param name="sequence" select="''"/>
  <xsl:param name="position" select="''"/>
  <xsl:param name="gentext-key" select="''"/>

<!--
  <fo:block>
    <xsl:value-of select="$pageclass"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="$sequence"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="$position"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="$gentext-key"/>
  </fo:block>
-->

  <fo:block>
    <!-- pageclass can be front, body, back -->
    <!-- sequence can be odd, even, first, blank -->
    <!-- position can be left, center, right -->
    <xsl:choose>
      <xsl:when test="$pageclass = 'titlepage'">
        <!-- nop; no footer on title pages -->
      </xsl:when>

      <xsl:when test="$double.sided != 0 and $sequence = 'even'
                      and $position='left'">
        <fo:page-number/>
      </xsl:when>

      <xsl:when test="$double.sided != 0 and ($sequence = 'odd' or $sequence = 'first')
                      and $position='right'">
        <fo:page-number/>
      </xsl:when>

      <xsl:when test="$double.sided = 0 and $position='right'">
        <fo:page-number/>
      </xsl:when>

      <xsl:when test="$double.sided = 0 and $position='center'">
        <xsl:value-of select="ancestor-or-self::book/info/title"/>
      </xsl:when>

      <xsl:when test="$sequence='blank'">
        <xsl:choose>
          <xsl:when test="$double.sided != 0 and $position = 'left'">
            <fo:page-number/>
          </xsl:when>
          <xsl:when test="$double.sided = 0 and $position = 'center'">
            <fo:page-number/>
          </xsl:when>
          <xsl:otherwise>
            <!-- nop -->
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>


      <xsl:otherwise>
        <!-- nop -->
      </xsl:otherwise>
    </xsl:choose>
  </fo:block>
</xsl:template>

 

另外,html的footer和header,暂时懒得去弄了。

有空再弄。

 

【总结】

还是没有完全搞懂啊。。。

转载请注明:在路上 » 【记录】docbook为html,pdf添加页眉和页脚

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (9)

  1. 你这个评论不太好使
    sunsolve10年前 (2013-12-10)回复
  2. 'ancestor-or-self::d:book/d:info/d:title'
    sunsolve10年前 (2013-12-10)回复
  3. sunsolve10年前 (2013-12-10)回复
  4. ancestor-or-self::d:book/d:info/d:title
    sunsolve10年前 (2013-12-10)回复
  5. 就可以在页眉或者页脚显示出文章的标题了
    sunsolve10年前 (2013-11-28)回复
    • 你评论中发了html内容?如果是,则已被屏蔽,无法显示,所以看不到你的解决办法。
      crifan10年前 (2013-12-02)回复
      • 添加命名空间 xmlns:d="http://docbook.org/ns/docbook ,然后通过 方式来获取 title的值就可以了
        sunsolve10年前 (2013-12-10)回复
        • xsl:value-of select="ancestor-or-self::d:book/d:info/d:title
          sunsolve10年前 (2013-12-10)回复
          • 你这个评论功能不太好使
            sunsolve10年前 (2013-12-10)回复
93 queries in 0.153 seconds, using 22.14MB memory