1

HTML に変換するために、すべて 1 つの DocBook ファイルにマージされる DocBook XML ファイルがたくさんあります。個々のドキュメントはリファレンス ページです (関数または同様の構造の)。各参照ページが独自の HTML ページになるように、チャンク HTML 生成を使用します。

問題は次のとおりです。各ページに目次が必要です。しかし、そのページの目次は必要ありません。リファレンス マニュアル全体の完全な TOC が必要です。

つまり、どのページからでも、TOC を使って他のページにジャンプできるようにしたいのです。CSS スタイルを使用して、TOC を左側に貼り付けることができます (モバイル表示などのために非表示にすることもできます)。

これを処理する明白な方法があります。後処理スクリプトを使用してメインの目次を抽出し、スクリプトでこれを各出力 HTML ドキュメントにコピーすることができます。私が探しているのは、DocBook XSL 内で動作する方法です。

DocBook XSL の新しい webhelp のような結果が得られるようにしたいのですが、JavaScript の関与があまり目立たないようにしたいと考えています。

4

2 に答える 2

2

2019-07-06 の docbook-xsl-1.79.2 の時点で、現在受け入れられている回答は、各目次を完成させるのに十分ではありません。

ただし、次の XSL テンプレートはそうです。重要な洞察は、Oxygen XML エディターのデバッガーを使用toc-contextして、ルート要素に正しく設定されている一方で、nodes変数がまだローカル サブセットであることに気付いたことです。

変更を取り消しましたtoc-contextroot-nodes代わりに、を選択して新しい変数を作成し、代わりに使用するようにテンプレートを/編集しましたmake.tocroot-nodesnodes.

これをカスタマイズ レイヤーに配置すると、すべての目次が完全な目次になります。

<xsl:template name="make.toc">
  <xsl:param name="toc-context" select="."/>
  <xsl:param name="toc.title.p" select="true()"/>
  <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
  <xsl:variable name="root-nodes" select="/"/>

  <xsl:variable name="nodes.plus" select="$root-nodes | d:qandaset"/>

  <xsl:variable name="toc.title">
   <xsl:if test="$toc.title.p">
    <xsl:choose>
     <xsl:when test="$make.clean.html != 0">
      <div class="toc-title">
       <xsl:call-template name="gentext">
        <xsl:with-param name="key">TableofContents</xsl:with-param>
       </xsl:call-template>
      </div>
     </xsl:when>
     <xsl:otherwise>
      <p>
       <strong>
        <xsl:call-template name="gentext">
         <xsl:with-param name="key">TableofContents</xsl:with-param>
        </xsl:call-template>
       </strong>
      </p>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:if>
  </xsl:variable>

  <xsl:choose>
   <xsl:when test="$manual.toc != ''">
    <xsl:variable name="id">
     <xsl:call-template name="object.id"/>
    </xsl:variable>
    <xsl:variable name="toc" select="document($manual.toc, .)"/>
    <xsl:variable name="tocentry" select="$toc//d:tocentry[@linkend=$id]"/>
    <xsl:if test="$tocentry and $tocentry/*">
     <div class="toc">
      <xsl:copy-of select="$toc.title"/>
      <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
       <xsl:call-template name="toc.list.attributes">
        <xsl:with-param name="toc-context" select="$toc-context"/>
        <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
        <xsl:with-param name="nodes" select="$root-nodes"/>
       </xsl:call-template>
       <xsl:call-template name="manual-toc">
        <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
       </xsl:call-template>
      </xsl:element>
     </div>
    </xsl:if>
   </xsl:when>
   <xsl:otherwise>
    <xsl:choose>
     <xsl:when test="$qanda.in.toc != 0">
      <xsl:if test="$nodes.plus">
       <div class="toc">
        <xsl:copy-of select="$toc.title"/>
        <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
         <xsl:call-template name="toc.list.attributes">
          <xsl:with-param name="toc-context" select="$toc-context"/>
          <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
          <xsl:with-param name="nodes" select="$root-nodes"/>
         </xsl:call-template>
         <xsl:apply-templates select="$nodes.plus" mode="toc">
          <xsl:with-param name="toc-context" select="$toc-context"/>
         </xsl:apply-templates>
        </xsl:element>
       </div>
      </xsl:if>
     </xsl:when>
     <xsl:otherwise>
      <xsl:if test="$root-nodes">
       <div class="toc">
        <xsl:copy-of select="$toc.title"/>
        <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
         <xsl:call-template name="toc.list.attributes">
          <xsl:with-param name="toc-context" select="$toc-context"/>
          <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
          <xsl:with-param name="nodes" select="$root-nodes"/>
         </xsl:call-template>
         <xsl:apply-templates select="$root-nodes" mode="toc">
          <xsl:with-param name="toc-context" select="$toc-context"/>
         </xsl:apply-templates>
        </xsl:element>
       </div>
      </xsl:if>
     </xsl:otherwise>
    </xsl:choose>

   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

注:チャンクされたすべてのページが独自の ToC を取得するわけではないという問題が残っていますが、これはこれとは関係ありません。並べ替えたら、それをどのように行ったかについてコメントを追加します。

于 2019-07-06T19:02:27.750 に答える