【问题】
已经可以通过ant webhelp给docbook生成对应的在线帮助系统。
但是生成出来的左边目录中,没有了章节编号,没了索引号:
所以想要添加进去。
【解决过程】
1.关于目录的索引编号,其实之前就已经折腾过,但是是针对html/pdf的,相关xsl配置为:
1 2 3 4 5 6 7 8 9 10 11 | <!--============================================================================ TOC index setting =============================================================================--> <!-- 自动添加(索引)编号 --> < xsl:param name = "section.autolabel" select = "1" /> <!-- 添加的编号中包括子的小节 --> < xsl:param name = "section.label.includes.component.label" select = "1" /> <!-- 引用Reference部分也编号 --> < xsl:param name = "bibliography.numbered" select = "1" /> <!-- TOC目录最大深度,默认是5 --> < xsl:param name = "toc.section.depth" >8</ xsl:param > |
然后将其加入进来,然后编出来的效果是:
即左边的TOC还是没有章节编号,但是正文中的内容,包括正文里面的目录,倒是出现了所希望的目录编号。
所以,还是要继续折腾,让左边的TOC也添上章节的索引编号。
2.后来找到了上述左边的TOC所对应的html源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <ul id= "tree" class= "filetree" > <li><span class= "file" ><a href= "preface.html" tabindex= "1" >Docbook介绍</a></span><ul> <li><span class= "file" ><a href= "what_is_docbook.html" tabindex= "1" >什么是Docbook</a></span><ul> <li><span class= "file" ><a href= "pr01s01s01.html" tabindex= "1" >Docbook出现的背景</a></span></li> <li><span class= "file" ><a href= "pr01s01s02.html" tabindex= "1" >Docbook是什么</a></span><ul> <li><span class= "file" ><a href= "pr01s01s02s01.html" tabindex= "1" >截图说明Docbook的:一种(xml)格式输入,多种(html,htmls,chm,pdf,txt,rtf等等)格式输出</a></span><ul> <li><span class= "file" ><a href= "pr01s01s02s01.html#d0e287" tabindex= "1" >Docbook的一种输入:xml源码(文件)</a></span></li> <li><span class= "file" ><a href= "pr01s01s02s01.html#d0e304" tabindex= "1" >Docbook的多种输出:HTML,HTMLs,PDF,CHM,RTF,TXT等格式</a></span></li> </ul> </li> </ul> </li> </ul> </li> <li><span class= "file" ><a href= "why_use_docbook.html" tabindex= "1" >我为何选择Docbook</a></span></li> </ul> </li> |
然后就去找相关的是哪里的xsl生成的上述的代码的。
然后找到了是在
E:\Dev_Root\docbook\dev\ant\webhelp\xsl\webhelp-common.xsl
中的
1 2 3 4 5 6 7 8 9 10 11 12 | < div id = "treeDiv" > < img src = "{$webhelp.common.dir}images/loading.gif" alt = "loading table of contents..." id = "tocLoading" style = "display:block;" /> < div id = "ulTreeDiv" style = "display:none" > < ul id = "tree" class = "filetree" > < xsl:apply-templates select = "/*/*" mode = "webhelptoc" > < xsl:with-param name = "currentid" select = "$currentid" /> </ xsl:apply-templates > </ ul > </ div > </ div > |
这部分xsl生成的html,那接着就是想办法,对其添加索引编号的配置了。
3.然后在webhelp-common.xsl看到了:
1 2 3 4 5 6 7 8 9 10 11 12 | < xsl:when test = "$rootid != ''" > < xsl:variable name = "title" > < xsl:if test = "$webhelp.autolabel=1" > < xsl:variable name = "label.markup" > < xsl:apply-templates select = "key('id',$rootid)" mode = "label.markup" /> </ xsl:variable > < xsl:if test = "normalize-space($label.markup)" > < xsl:value-of select = "concat($label.markup,$autotoc.label.separator)" /> </ xsl:if > </ xsl:if > < xsl:apply-templates select = "key('id',$rootid)" mode = "titleabbrev.markup" /> </ xsl:variable > |
中有$webhelp.autolabel,所以,又是之前折腾的很熟悉的webhelp相关的参数了。
所以就去网上找到相关的配置参数的解释:
DocBook XSL Stylesheets: Reference Documentation
对于html的参数,就找到了:
中的:
webhelp.autolabel — Should tree-like ToC use autonumbering feature? webhelp.base.dir — The base directory for webhelp output. webhelp.common.dir — Path to the directory for the common webhelp resources (JavaScript, css, common images, etc). webhelp.default.topic — The name of the file to which the start file in the webhelp base directory redirects webhelp.include.search.tab — Should the webhelp output include a Search tab? webhelp.indexer.language — The language to use for creating the webhelp search index. webhelp.start.filename — The name of the start file in the webhelp base directory. webhelp.tree.cookie.id — Controls how the cookie that stores the webhelp toc state is named.
所以,就可以去试试各个参数的效果了。
4.先去添加了:
1 | < xsl:param name = "webhelp.autolabel" >1</ xsl:param > |
然后编译后,就可以看到TOC带索引编号了:
5.但是很明显,章节前面还是没有第一章,第二章等编号。
但是很奇怪的上述参数的解释却是:
To include chapter and section numbers the table of contents pane, set this parameter to 1.
即包含了chapter的编号。
所以就是出现了,虽然参数解释中说加了此参数可以将chapter和section都加index,但是实际只是section加了index,而chapter没有。
不知道是不是bug。
6.然后就去继续去折腾。后来在webhelp-common.xsl中看到了一些参数:
1 2 3 4 5 6 7 | < xsl:param name = "section.autolabel" select = "0" /> < xsl:param name = "chapter.autolabel" select = "0" /> < xsl:param name = "appendix.autolabel" select = "0" /> < xsl:param name = "qandadiv.autolabel" select = "0" /> < xsl:param name = "reference.autolabel" select = "0" /> < xsl:param name = "part.autolabel" select = "0" /> < xsl:param name = "section.label.includes.component.label" select = "1" /> |
所以就去先添加一个:
1 | < xsl:param name = "chapter.autolabel" select = "1" /> |
试试,结果就可以给chapter添加索引编号了:
其中,注意到,preface,appendix等是没有编号的。
7.所以,就又去添加相关的配置参数:
1 2 3 | < xsl:param name = "appendix.autolabel" select = "1" /> < xsl:param name = "qandadiv.autolabel" select = "1" /> < xsl:param name = "reference.autolabel" select = "1" /> |
去给appendix,qandadiv,reference,都加上索引编号,然后编译结果是appendix加了索引编号,倒是更加不好看了,所以又把appendix.autolabel改为0.
8.最后,TOC的效果如下:
然后后来又添加个navig.showtitles,最后效果为:
【总结】
想要给webhelp的TOC添加索引编号,通过其内在就支持的参数配置,即可实现。
目前,此处个人手动添加的几个配置为:
1 2 3 4 5 6 7 | < xsl:param name = "webhelp.autolabel" >1</ xsl:param > < xsl:param name = "chapter.autolabel" select = "1" /> < xsl:param name = "appendix.autolabel" select = "0" /> < xsl:param name = "qandadiv.autolabel" select = "1" /> < xsl:param name = "reference.autolabel" select = "1" /> < xsl:param name = "navig.showtitles" >1</ xsl:param > |
即可实现想要的效果了。
转载请注明:在路上 » 【已解决】给ant的webhelp生成的TOC目录添加索引号