Xslt DITA bookmaps中PDF输出的带零件和不带零件的带编号书签
我正在尝试使用DITA OT和自定义插件创建带有编号标题的PDF输出。默认情况下,输出包含标题和TOC中的零件号、章节号和附录号,但书签中没有数字。到目前为止,我已经成功地对标题和TOC中的所有剩余主题进行了编号,如下所示(每个部分的章节编号重新开始):Xslt DITA bookmaps中PDF输出的带零件和不带零件的带编号书签,xslt,dita,Xslt,Dita,我正在尝试使用DITA OT和自定义插件创建带有编号标题的PDF输出。默认情况下,输出包含标题和TOC中的零件号、章节号和附录号,但书签中没有数字。到目前为止,我已经成功地对标题和TOC中的所有剩余主题进行了编号,如下所示(每个部分的章节编号重新开始): 图书地图 第一部分 第一章 专题1.1 专题1.2 第二章 第二部分 第一章 但是,我无法获得相同的书签编号 我使用以下代码(或覆盖)选择必须编号的书签: <xsl:template match="*[cont
- 图书地图
- 第一部分
- 第一章
- 专题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中的一个示例):
使用此代码,零件、附录和不带零件的图书地图将正确编号。但是,对于带有零件的图书地图,章节是连续编号的,这是不一致的
- 图书地图
- 第一部分
- 第一章
- 专题1.1
- 专题1.2
- 第二章
- 第一章
- 第二部分
- 第三章
- 第一部分
有谁能帮我纠正这个问题吗?我刚刚找到了一种方法来获得我想要的结果。计算带有零件的图书地图章节号的代码修改如下:
<!-- 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>
这可能一点也不优雅,但我是一名技术作家……您能提供源XML吗?这将使回答您更容易。我有一个公共要点,如果您可以将相关部分合并到问题中以创建一个链接,这将更好,因为链接可能随时消失。因此,当您使用
将变量topicChapters
绑定到章节副本时,是否无法保留层次结构?您复制的那些元素不是包含在零件的父元素中吗?这样您就应该复制零件或将其转换为包含您感兴趣的章节?显然,在您当前的方法中,您的变量包含一个简单的元素列表,当您计算同级元素时,您最终会看到前面的所有章节。是的,您是对的。我找到了一种解决方法(在我看来不是很优雅,但我可以做到):当我有一个带有零件的bookmap时,我忽略topicChapters变量。
<!-- 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>