从 DITA 书签地图输出的 PDF 中的编号书签,带和不带部分



我正在尝试使用 DITA OT 和自定义插件创建带有编号标题的 PDF 输出。默认情况下,输出在标题和目录中包含部件号、章节号和附录号,但在书签中不包含数字。到目前为止,我已经设法对标题和目录中的所有剩余主题进行了编号,如下所示(章节编号在每个部分中重新开始):

  • 书籍地图
    • 第一部分
      • 第一章
        • 主题 1.1
        • 主题 1.2
      • 第二章
    • 第二部分
      • 第一章

但是,我无法获得相同的书签数字。

我使用以下代码(或覆盖)来选择必须编号的书签:

<xsl:template match="*[contains(@class, ' topic/topic ')]" mode="bookmark">
<xsl:variable name="mapTopicref" select="key('map-id', @id)[1]"/>
<xsl:variable name="topicTitle">
<xsl:call-template name="getNavTitle"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$mapTopicref[@toc = 'yes' or not(@toc)] or
not($mapTopicref)">
<fo:bookmark>
<xsl:attribute name="internal-destination">
<xsl:call-template name="generate-toc-id"/>
</xsl:attribute>
<xsl:if test="$bookmarkStyle!='EXPANDED'">
<xsl:attribute name="starting-state">hide</xsl:attribute>
</xsl:if>
<fo:bookmark-title>
<xsl:choose>
<xsl:when test="contains($mapTopicref/@class, ' bookmap/part ')">
<xsl:call-template name="getChapterPrefix"/>
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="contains($mapTopicref/@class, ' bookmap/appendix ')">
<xsl:call-template name="getChapterPrefix"/>
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="contains($mapTopicref/@class, ' bookmap/chapter ')">
<xsl:call-template name="getChapterPrefix"/>
<xsl:text> </xsl:text>
</xsl:when>
</xsl:choose>
<xsl:value-of select="normalize-space($topicTitle)"/>
</fo:bookmark-title>
<xsl:apply-templates mode="bookmark"/>
</fo:bookmark>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="bookmark"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

我使用以下代码来创建数字(派生自 DITA for Print 中的示例):

<xsl:template name="getChapterPrefix">
<xsl:variable name="topicType">
<xsl:call-template name="determineTopicType"/>
</xsl:variable>
<xsl:variable name="partsCount">
<xsl:value-of select="count($map//*[contains(@class, ' bookmap/part')])"/>
</xsl:variable>
<xsl:variable name="containingChapter" select="ancestor-or-self::*[contains(@class, ' topic/topic')][position()=1]"/>
<xsl:variable name="id" select="$containingChapter/@id"/>
<xsl:variable name="topicChapters">
<xsl:copy-of select="$map//*[contains(@class, ' bookmap/chapter')]"/>
</xsl:variable>
<xsl:variable name="topicAppendices">
<xsl:copy-of select="$map//*[contains(@class, ' bookmap/appendix')]"/>
</xsl:variable>
<xsl:variable name="topicParts">
<xsl:copy-of select="$map//*[contains(@class, ' bookmap/part')]"/>
</xsl:variable>
<xsl:variable name="chapterNumber">
<xsl:choose>
<xsl:when test="$topicChapters/*[@id = $id]">
<xsl:choose>
<xsl:when test="$partsCount=0"> <!-- Bookmaps without parts work fine -->
<xsl:number format="1" value="count($topicChapters/*[@id =$id]/preceding-sibling::*) + 1"/>                           
</xsl:when>
<xsl:otherwise> <!-- This does not work yet. -->
<xsl:number format="1" value="count($topicChapters/*[@id =$id]/preceding-sibling::*) + 1"/>                
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$topicAppendices/*[@id = $id]">
<xsl:number format="A" value="count($topicAppendices/*[@id =$id]/preceding-sibling::*) + 1"/>
</xsl:when>
<xsl:when test="$topicParts/*[@id = $id]">
<xsl:number format="I" value="count($topicParts/*[@id =$id]/preceding-sibling::*) + 1"/>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable> 
<xsl:choose>
<xsl:when test="$chapterNumber != ''">
<xsl:value-of select="$chapterNumber"/>
</xsl:when>
</xsl:choose>
</xsl:template>

使用此代码,没有部件的部件、附录和书籍地图将正确编号。但是,对于带有零件的书籍地图,章节是连续编号的,这是不一致的。

  • 书籍地图
    • 第一部分
      • 第一章
        • 主题 1.1
        • 主题 1.2
      • 第二章
    • 第二部分
      • 第3章

谁能帮我纠正这个问题?

我刚刚找到了一种方法来获得我想要的结果。计算带有部件的书籍地图的章节编号的代码段经过修改如下:

<!-- If there's something in $topicChapters with an id that matches the id of the
context node, then I'm inside a chapter. -->
<xsl:when test="$topicChapters/*[@id = $id]">
<xsl:choose>
<xsl:when test="$partsCount=0"> <!-- Bookmaps without parts -->
<xsl:number format="1" value="count($topicChapters/*[@id =$id]/preceding-sibling::*) + 1"/>                           
</xsl:when>
<xsl:otherwise> <!-- Bookmaps with parts. -->
<xsl:number format="1" value="count(//*[contains(@class,' bookmap/chapter ')][@id =$id]/preceding-sibling::*)"/>                
</xsl:otherwise>
</xsl:choose>
</xsl:when>

这可能只是优雅的一切,但是,我是一名技术作家......

最新更新