使用DocBook / XSLT-FO生成每章下的部分TOC

问题描述 投票:1回答:1

我正在使用FOP 2.3,我有以下内容:

<book>
  <chapter>
    <title>ChA</title>
    <section>
      <title>Structures</title>
      <xi:include href="struct1.xml"/>
    </section>
    <section>
      <title>Functions</title>
      <xi:include href="function1.xml"/>
    </section>
  </chapter>
</book>

对于function1.xml(作为例子),我有:

<refentry xml:id="some_func" version="5.0">
  <refmeta>
    <refentrytitle>SomeFunc</refentrytitle>
  </refmeta>
  ...
</refentry>

是否有可能...

  1. 不列出refentrys之间的部分,但只列在章节标题下作为迷你ToC?
  2. 列出每个部分下的refentry/refentrytitle值?

例如,ChA章节开头的输出应如下所示:

Page X
       ChA
         Structures
           SomeStruct
         Functions
           SomeFunc

Page X+1
       SomeStruct page

Page X+2
       SomeFunc page

Page X+3
       ChB
         Structures
           SomeStruct2
         Functions
           SomeFunc2
...

接下来的新页面按顺序呈现ChA章节的所有部分中的每个refentry,并且不会被结构和函数部分分解。

编辑1

我能够阻止在手册页之间打印部分。我复制了section.content模板:

<xsl:template name="section.content">
  <!-- Don't display section -->
  <!-- <xsl:call-template name="section.titlepage"/> -->
  ...
</xsl:template>

至于列出这些部分,我发现了这个:

<xsl:template match="chapter">
  ...
  <fo:page-sequence hyphenate="{$hyphenate}"
                    master-reference="{$master-reference}">
    ...
    <fo:flow flow-name="xsl-region-body">
      <xsl:call-template name="set.flow.properties">
        <xsl:with-param name="element" select="local-name(.)"/>
        <xsl:with-param name="master-reference" select="$master-reference"/>
      </xsl:call-template>

      <fo:block id="{$id}"
                xsl:use-attribute-sets="component.titlepage.properties">
        <xsl:call-template name="chapter.titlepage"/>
        <!-- === HERE IS WHERE I AM INSERTING MY CUSTOM TABLE OF CONTENTS === -->
        <xsl:for-each select="self::*/section">
          <fo:block>
            <xsl:message>DEBUG><xsl:value-of select="title"/></xsl:message>
            <xsl:value-of select="title"/>

            <xsl:for-each select="self::*/refentry/refmeta">
              <fo:block>
                <xsl:value-of select="refentrytitle"/>
              </fo:block>
            </xsl:for-each>
          </fo:block>
        </xsl:for-each>

      </fo:block>

      <xsl:call-template name="make.component.tocs"/>

      <xsl:apply-templates/>
    </fo:flow>
  </fo:page-sequence>
</xsl:template>
xml xslt apache-fop docbook
1个回答
0
投票

花了一段时间。

首先,必须在自定义样式文件中覆盖chapter模板:

<xsl:template match="chapter">
  ...
    <fo:flow flow-name="xsl-region-body">
      <xsl:call-template name="set.flow.properties">
        <xsl:with-param name="element" select="local-name(.)"/>
        <xsl:with-param name="master-reference" select="$master-reference"/>
      </xsl:call-template>

      <xsl:call-template name="chapter.titlepage"/>

      <!-- Call Table of contents name here -->
      <xsl:call-template name="table.of.contents.titlepage.recto.sony"/>

      <fo:block id="{$id}" xsl:use-attribute-sets="component.titlepage.properties">
        <xsl:for-each select="self::*/section">
          <fo:block start-indent="{count(ancestor::*) + 2}pc">
            <xsl:variable name="section.id">
              <xsl:call-template name="object.id"/>
            </xsl:variable>

            <!-- XXX: Error if "title" element doesn't exist -->
            <xsl:value-of select="title"/>
          </fo:block>

          <!-- XXX: Error if "refnamediv" doesn't exist -->
          <xsl:for-each select="self::*/refentry/refnamediv">
            <fo:block xsl:use-attribute-sets="toc.line.properties" start-indent="{count(ancestor::*) + 2}pc">
              <xsl:variable name="refname.id">
                <xsl:call-template name="object.id"/>
              </xsl:variable>

              <!-- XXX: Error if "refname" doesn't exist -->
              <fo:inline font-family="Courier" keep-with-next.within-line="always">
                <fo:basic-link internal-destination="{$refname.id}">
                  <xsl:value-of select="refname"/>
                </fo:basic-link>
              </fo:inline>

              <fo:inline keep-together.within-line="always">
                <fo:leader leader-pattern="space"
                           keep-with-next.within-line="always"/>
                <fo:basic-link internal-destination="{$id}">
                  <fo:page-number-citation ref-id="{$refname.id}"/>
                </fo:basic-link>
              </fo:inline>

            </fo:block>
          </xsl:for-each>

        </xsl:for-each>
      </fo:block>

      <xsl:call-template name="make.component.tocs"/>

      <xsl:apply-templates/>
    </fo:flow>
  </fo:page-sequence>
</xsl:template>

以上将显示每章目录。该部分需要省略:

<xsl:template name="section.content">
  <!-- Don't display section -->
  <!-- <xsl:call-template name="section.titlepage"/> -->
  ...
</xsl:template>
© www.soinside.com 2019 - 2024. All rights reserved.