【问题】
docbook中,已经实现了callout的co,可以放在chapter的任意位置,然后可以在别处通过coref去引用,生成的pdf和html中,对应的callout的bug图标,也都可以正常显示了。但是目前由于所涉及条目较多,会超过20(甚至30),而由于目前callout 的编号所对应图片(svg和png),最大只有30,所以,此处希望对于callout超过20,就让其重新编号,使得后续的callout可以继续从1继续编号到20,这样就可以正常显示了。
当前的docbook源码为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | < p >< orderedlist > < listitem >< emphasis >Evacuation</ emphasis >< co id = "co.evacuation" linkends = "co.note.evacuation" /> procedures are implemented whenever the fire alarms have been activated.</ listitem > < listitem >The following rules and policies are binding for every employee who works at the < emphasis >premises</ emphasis >< co id = "co.premises" linkends = "co.note.premises" /> of M&M Software (Suzhou) GmbH</ listitem > < listitem >This also includes employees from M&M Software in Sankt Georgen who work in Suzhou permanently ('< emphasis >Expatriates</ emphasis >< co id = "co.expatriates" linkends = "co.note.expatriates" />') or who are just visiting the offices temporarily.</ listitem > < listitem >The office shall not be used for private or < emphasis >recreational</ emphasis >< co id = "co.recreational" linkends = "co.note.recreational" /> purposes.</ listitem > < listitem >The < emphasis >electronic attendance system</ emphasis >< co id = "co.elec_attend_system" linkends = "co.note.elec_attend_system" /> in connection with the personal card shall only be used by using one’s own card.</ listitem > < listitem >The business divisions Factory Automation and Process Automation develop technologically outstanding and innovative PC and Web based solutions for < emphasis >renowned</ emphasis >< co id = "co.renowned" linkends = "co.note.renowned" /> industrial customers.</ listitem > < listitem >< emphasis >Synergy-effects</ emphasis >< co id = "co.synerygy_effect" linkends = "co.note.synerygy_effect" /> between the business divisions will also reflect positively on our technological leadership</ listitem > < listitem >Our main < emphasis >turnover</ emphasis >< co id = "co.turnover" linkends = "co.note.turnover" /> is based on software development services in our target sector Industrial Automation.</ listitem > < listitem >They must be able to work in a safe, pleasant and < emphasis >appealing</ emphasis >< co id = "co.appealing" linkends = "co.note.appealing" /> workplace and working environment.</ listitem > < listitem >We also want to create an environment, where they can gain < emphasis >personal satisfaction and self-esteem</ emphasis >< co id = "co.satif_and_esteem" linkends = "co.note.satif_and_esteem" /> from their work.</ listitem > < listitem >Therefore we support Product < emphasis >Envisioning</ emphasis >< co id = "co.envisioning" linkends = "co.note.envisioning" /> and -Implementation</ listitem > < listitem >The personal files of the employees will < emphasis >be entrusted to</ emphasis >< co id = "co.trusted_to" linkends = "co.note.trusted_to" /> the company and be kept by its filing agent.</ listitem > < listitem >They asked us to do a < emphasis >retrospective</ emphasis >< co id = "co.retrospective" linkends = "co.note.retrospective" /> about the first months of that project.</ listitem > < listitem >This FieldBus Kit (FBK) is an < emphasis >off-the shelf</ emphasis >< co id = "co.off_the_shelf" linkends = "co.note.off_the_shelf" />, proven solution for the rapid development of FOUNDATIONTM fieldbus H1 (FF H1) and PROFIBUS PA (PB PA) field devices for intrinsically and non-intrinsically safe environments.</ listitem > < listitem >The < emphasis >trendsetting</ emphasis >< co id = "co.trendsetting" linkends = "co.note.trendsetting" /> FBK module is utilizing Softing’s communication ASIC UFC100-F1.</ listitem > < listitem >The FBK module has an < emphasis >intrinsically</ emphasis >< co id = "co.intrinsically" linkends = "co.note.intrinsically" /> safe design and has an ATEX certification.</ listitem > < listitem >Relatively high < emphasis >fluctuation</ emphasis >< co id = "co.fluctuation" linkends = "co.note.fluctuation" /> (but no big impact). </ listitem > < listitem >System Control < emphasis >Fair</ emphasis >< co id = "co.fair_exhibitor" linkends = "co.note.fair_exhibitor" /> 2009,exhibitor< coref linkend = "co.fair_exhibitor" /></ listitem > < listitem >PROFIBUS enables < emphasis >proactive</ emphasis >< co id = "co.proactive" linkends = "co.note.proactive" /> management over the life cycle of a plant.</ listitem > < listitem >A broad spectrum of base technology components and development tools (PROFIBUS ASICs, PROFIBUS stacks, bus monitors, test tools and < emphasis >commissioning</ emphasis >< co id = "co.commissioning" linkends = "co.note.commissioning" /> tools) and services are available for implementation of the PROFIBUS protocol.</ listitem > </ orderedlist > < table xml:id = "tbl.eng_words_1_20" >< title >1-20单词的含义</ title > < tgroup cols = "4" > < colspec colnum = "1" colname = "col1" colwidth = "1*" /> < colspec colnum = "2" colname = "col2" colwidth = "2*" /> < colspec colnum = "3" colname = "col3" colwidth = "2*" /> < colspec colnum = "4" colname = "col4" colwidth = "4*" /> < thead align = "center" > < row >< entry >序号</ entry >< entry >英文单词</ entry >< entry >中文含义</ entry >< entry >说明注释</ entry ></ row > </ thead > < tbody > < row >< entry >< coref linkend = "co.evacuation" id = "co.note.evacuation" /></ entry >< entry >evacuation</ entry >< entry >疏散,撤离</ entry >< entry >指失火了,要逃离的情况</ entry ></ row > ......</ p >< p > </ tbody > </ tgroup > </ table > < orderedlist > < listitem >Additionally, PI competence Center and many suppliers offer support < emphasis >in this regard</ emphasis >< co id = "co.in_this_regard" linkends = "co.note.in_this_regard" />.</ listitem > < listitem >The technology reduces hardware requirements and lowers Capital Expenditures (< emphasis >CAPEX</ emphasis >< co id = "co.capex" linkends = "co.note.capex" />).</ listitem > < listitem >FOUNDATION HSE’s < emphasis >full-fledged</ emphasis >< co id = "co.full_fledged" linkends = "co.note.full_fledged" /> redundancy scheme gives control systems greater availability than systems using simple ring-topology.</ listitem > < listitem >A key < emphasis >tenet</ emphasis >< co id = "co.tenet" linkends = "co.note.tenet" /> of the Fieldbus Foundation is that the FOUNDATION protocol is non-proprietary and available to all companies wishing to include it in their product offerings.</ listitem > < listitem >The Fieldbus Kit allows applications in an intrinsically safe environment, and - due to its compact design - it can be used in < emphasis >a multitude of</ emphasis >< co id = "co.a_multitude_of" linkends = "co.note.a_multitude_of" /> existing devices.</ listitem > < listitem >The following table contains the language codes explicitly < emphasis >delineate</ emphasis >< co id = "co.delineate" linkends = "co.note.delineate" />d for RSS.</ listitem > < listitem >This signal is < emphasis >superimpose</ emphasis >< co id = "co.superimpose" linkends = "co.note.superimpose" />d at a low level on the 4-to-20mA analog measurement signal without causing any interference with the analog signal.</ listitem > </ orderedlist > < table xml:id = "tbl.eng_words_21_40" >< title >21-40单词的含义</ title > < tgroup cols = "4" > < colspec colnum = "1" colname = "col1" colwidth = "1*" /> < colspec colnum = "2" colname = "col2" colwidth = "2*" /> < colspec colnum = "3" colname = "col3" colwidth = "2*" /> < colspec colnum = "4" colname = "col4" colwidth = "4*" /> < thead align = "center" > < row >< entry >序号</ entry >< entry >英文单词</ entry >< entry >中文含义</ entry >< entry >说明注释</ entry ></ row > </ thead > < tbody > < row >< entry >< coref linkend = "co.in_this_regard" id = "co.note.in_this_regard" /></ entry >< entry >in this regard</ entry >< entry >就这一点而言,针对这点(来说)</ entry >< entry ></ entry ></ row > < row >< entry >< coref linkend = "co.capex" id = "co.note.capex" /></ entry >< entry >Capital Expenditures (CAPEX)</ entry >< entry >资本支出</ entry >< entry >Capital Expenditure缩写为CAPEX,一般是指资金、固定资产的投入.对电信运营商来说,有关的网络设备、计算机、仪器等一次性支出的项目都属于CAPEX。与之对应的叫做OPEX,Operating Expense,运营(管理)支出(成本)</ entry ></ row > < row >< entry >< coref linkend = "co.full_fledged" id = "co.note.full_fledged" /></ entry >< entry >full-fledged</ entry >< entry >羽翼丰满的,成熟的</ entry >< entry ></ entry ></ row > < row >< entry >< coref linkend = "co.tenet" id = "co.note.tenet" /></ entry >< entry >tenet</ entry >< entry >信条,原则</ entry >< entry ></ entry ></ row > < row >< entry >< coref linkend = "co.a_multitude_of" id = "co.note.a_multitude_of" /></ entry >< entry >a multitude of</ entry >< entry >大量的</ entry >< entry >相当于many,much</ entry ></ row > < row >< entry >< coref linkend = "co.delineate" id = "co.note.delineate" /></ entry >< entry >delineate</ entry >< entry >描述,描绘</ entry >< entry ></ entry ></ row > < row >< entry >< coref linkend = "co.superimpose" id = "co.note.superimpose" /></ entry >< entry >superimpose</ entry >< entry >叠加,置于他物之上</ entry >< entry >可用于指两种信号叠加</ entry ></ row > </ tbody > </ tgroup > </ table ></ p > |
对应的html和pdf中生成的效果为:
希望第二个orderedlist中的co可以重新编号,从1开始,而不是从21开始。
【解决过程】
1.后来在
Part 2. FO Parameter Reference
和
Part 1. HTML Parameter Reference
中找到关于callout方面的参数:
callout.graphics.number.limit,但却发现,其知只能指定最大编号的限制,超过了编号,没法重新编号,只是会用文字版代替图片(plain text instead of a graphic)。
2.搜了半天,网上也找不到任何有关callout重新编号方面的内容。
看来只能自己试着看看能否通过修改xsl配置去实现了。
3.先是去看了fo中的代码,然后把对应的编号21改为1,变成:
1 2 3 4 5 | < p > </ fo:list-item-label > < fo:list-item-body start-indent = "body-start()" > < fo:block >Additionally, PI competence Center and many suppliers offer support < fo:inline color = "brown" >in this regard</ fo:inline >< fo:inline >< fo:basic-link internal-destination = "co.note.in_this_regard" id = "co.in_this_regard" >< fo:external-graphic content-width = "7pt" width = "7pt" src = "url(D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/images/system/callouts/1.svg)" /></ fo:basic-link ></ fo:inline >.</ fo:block > </ fo:list-item-body > </ fo:list-item ></ p >< p >....</ p >< p >< fo:block >< br > < fo:inline >< br > < fo:basic-link internal-destination = "co.in_this_regard" id = "co.note.in_this_regard" >< br > < fo:external-graphic content-width = "7pt" width = "7pt" src = "url(D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/images/system/callouts/1.svg)" />< br > </ fo:basic-link >< br > </ fo:inline >< br ></ fo:block ></ p > |
然后生成的pdf的效果为:
就是我所想要的了,即编号可以从1开始,但是其中的图标,都还是可以点击的,可以调转到对应的位置的。
不过对于如何去修改xsl配置以实现此目的,则还是暂时没有搞定。
3.目前所能想到的办法是,在想要重新编号的co中,添加对应的配置参数,比如
role="reindex",然后再去xsl中处理此处的co编号,让其从此处开始往后重新编号。
所以,把代码改为:
1 | < listitem >Additionally, PI competence Center and many suppliers offer support < emphasis >in this regard</ emphasis >< co role = "reindex" id = "co.in_this_regard" linkends = "co.note.in_this_regard" />.</ listitem > |
然后去找到对应callout所在xsl:
docbook-xsl-ns-1.77.0\fo\callout.xsl
然后找到了对应的处理callout的位置,是:
<xsl:template name="callout-bug">
其中对于发现callout是image的话,就去显示对应的callout的图片:
1 2 3 4 5 | < xsl:otherwise > < xsl:text >url(</ xsl:text > < xsl:value-of select = "$filename" /> < xsl:text >)</ xsl:text > </ xsl:otherwise > |
对应的$filename是上面定义出来的:
1 2 3 | < xsl:variable name = "filename" select="concat($callout.graphics.path, $conum, $callout.graphics.extension)"/> |
而此处的图片的索引,即为$conum,其是此模板的参数:
1 | < xsl:param name = "conum" select = '1' /> |
且学习了XSLT <xsl:param> 元素后,得知此处通过select去设置了默认值为1。
而此处编号已经变为了21,了,所以传递进来的图片地址是xxx\21.svg。
因此,此时还是要想办法,如果让此处的传入进来的值是1,而不是21.
4.然后就找到了,是在同一文件中:
1 2 3 4 5 6 7 8 9 10 | < xsl:template match = "d:co" mode = "callout-bug" > < xsl:call-template name = "callout-bug" > < xsl:with-param name = "conum" > < xsl:number count = "d:co" level = "any" from = "d:programlisting|d:screen|d:literallayout|d:synopsis" format = "1" /> </ xsl:with-param > </ xsl:call-template > </ xsl:template > |
去调用callout-bug的,其中传递的参数是conum。
然后又去学习XSLT <xsl:number> 元素,得知就是此处去计算co的值的。
从1开始,一点点往下面增加,直到此处的21.
所以,此处就是要去判断,如果有role="reindex"的话,就重新设置conum为1.
5.经过一番折腾,通过如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <!-- from docbook-xsl-ns-1.77.0\fo\callout.xsl --> < xsl:template match = "d:co" mode = "callout-bug" > < xsl:call-template name = "callout-bug" > < xsl:with-param name = "conum" > <!-- added by crifan start --> < xsl:choose > < xsl:when test = "@role" > < xsl:number value = "1" /> </ xsl:when > < xsl:otherwise > <!-- added by crifan end --> < xsl:number count = "d:co" level = "any" from = "d:programlisting|d:screen|d:literallayout|d:synopsis" format = "1" /> <!-- added by crifan start --> </ xsl:otherwise > </ xsl:choose > <!-- added by crifan end --> </ xsl:with-param > </ xsl:call-template > </ xsl:template > |
可以实现和上述手动把21改为1的同样的效果,也是可以自动生成1.svg了。
但是问题是,后续的编号还是从22开始的,而不是所期望的从2开始的。
6.目前所能想到的逻辑是,对于callout的index计数来说,
要设计一个lastCoPos为(programlisting或全文的)最开始,然后接下来的每个callout的计数都是根据lastCoPos来确定的,每次加1,这样就可以实现在role="reindex"后自动重新编号了。
但是经过一番折腾,由于对于xsl的语法不是足够清楚,所以还是失败了,没能搞定。
7.目前暂时的结果是:
参考Using position to count nodes – sometimes enumeration starts at 0 instead of 1和
Position of parent,写成的如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <!-- from docbook-xsl-ns-1.77.0\fo\callout.xsl --> < xsl:template match = "d:co" mode = "callout-bug" > < xsl:call-template name = "callout-bug" > <!-- changed by crifan start --> < xsl:with-param name = "conum" > <!-- <xsl:number count="d:co" level="any" from="d:programlisting|d:screen|d:literallayout|d:synopsis" format="1"/> --> < xsl:choose > < xsl:when test = "@role" > < xsl:number value = "1" /> </ xsl:when > < xsl:otherwise > < xsl:value-of select = "count(preceding-sibling::*)+1" /> </ xsl:otherwise > </ xsl:choose > </ xsl:with-param > <!-- changed by crifan end --> </ xsl:call-template > </ xsl:template > |
所得到的结果,只是全部都是2,reindex后的,全部都是1.
等待以后更加熟悉了xsl后,或许可以写出对应的配置,实现callout重新编号的功能。
另外,对于xsl:number的计数方面可供参考的资料,找到了一些:
转载请注明:在路上 » 【未解决】docbook中给callout的co重新编号