仅将元数据值添加到doc页面

时间:2017-03-10 22:51:27

标签: html docbook

我需要知道哪个页面是我们的Solr索引的html输出中的toc页面。我想添加一个元数据条目,将输出标识为toc。我尝试的所有内容都将价值放在所有页面中。我们正在使用docbook 4.5,而且我对xslt很新。任何指向正确方向的指针都将是一个很大的帮助。

谢谢!

1 个答案:

答案 0 :(得分:0)

我不认为DocBook XSL样式表提供了任何漂亮的方法,所以这是一个丑陋的黑客:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:import
    href="/usr/share/xml/docbook/stylesheet/docbook-xsl/html/chunk.xsl"/>
  <xsl:template name="head.content.generator">
    <xsl:param name="node" select="."/>
    <xsl:if test="not(parent::*)">
      <meta name="TOC" content="This is the TOC"/>
    </xsl:if>
    <meta name="generator" content="DocBook {$DistroTitle} V{$VERSION}"/>
  </xsl:template>
</xsl:stylesheet>

您需要将其放在名为docbook-custom.xsl的文件中并从XSLT引擎中调用它:

xsltproc docbook-custom.xsl BOOK.xml

docbook-custom.xsl“自定义层”文件中,您需要将href元素的xsl:import值设置为实际安装DocBook XSL样式表的位置。

http://www.sagehill.net/docbookxsl/CustomMethods.html#CustomizationLayer有一般细节。

当然,代替上面样式表中的<meta name="TOC" content="This is the TOC"/>,您希望将其更改为您要添加的实际meta元素。

此自定义图层自定义head.content.generator模板,使其能够将您实际设置的任何内容作为自定义meta元素,并在库存DocBook样式表的meta name="generator"元素之前注入自己输出。

<xsl:if test="not(parent::*)">…</xsl:if>导致样式表仅在第一个输出HTML“chunk”中输出自定义meta元素,默认情况下该名称为index.html,默认情况下为同一文件TOC包含在。