使用DocBook / XSLT-FO

时间:2018-08-26 02:35:42

标签: xml xslt apache-fop docbook

我正在使用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. 不是列出refentry之间的部分,而是仅以章节标题的形式列出它们作为迷你目录??
  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
...

下一个 new 页将按顺序依次渲染 ChA 章所有部分中的每个refentry,并且不会被 Structures 部分分解和功能

编辑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>

1 个答案:

答案 0 :(得分: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>