最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】用ant编译docbook生成webhelp过程中出错:Request for label of unexpected element: bibliodiv

Docbook crifan 1655浏览 0评论

【问题】

用ant编译Docbook源码,生成webhelp,中间过程提示错误信息Request for label of unexpected element: bibliodiv,详细log如下:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/language_summary/src
$ make webhelp
=============================== generating webhelp ==============================
ant webhelp
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\dev\books\language_summary\src\build.xml

validate:

clean:

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp
     [xslt] Processing E:\Dev_Root\docbook\dev\books\language_summary\src\language_summary.xml to E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp\null2144588655
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.1\profiling\profile.xsl
     [xslt] Processing E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp\null2144588655 to E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp\null2070826396
     [xslt] Loading stylesheet E:\Dev_Root\docbook\dev\ant\webhelp\xsl\webhelp_crl.xsl
     [xslt] language: en
     [xslt] Request for label of unexpected element: bibliodiv
     [xslt] Request for label of unexpected element: bibliodiv
     [xslt] Writing ../output/webhelp/content/ch01s01.html for sect1
......
     [xslt] Writing ../output/webhelp/content/index.html for book
     [xslt] Writing ../output/webhelp/index.html
     [xslt] Writing ../output/webhelp/content/search/l10n.js
     [copy] Copied 1 empty directory to 1 empty directory under E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp\content

index:
     [copy] Copying 1 file to E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp
     [copy] Copying 4 files to E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp
     [echo] Indexing html files in ../output/webhelp/content
     [java] Stemming enabled
     [java] The created index files are located in ..\output\webhelp\content\search\.js
     [java] Indexed the contents in 1 seconds

webhelp:

BUILD SUCCESSFUL
Total time: 8 seconds

此处的编译环境是:

cygwin + ant 1.8.4 +saxon 6.5.5 + docbook-xsl-ns 1.77.1

 

另外,之前用xsltproc编译其他格式,比如html,pdf等,都是正常的,没有此警告的。

 

【解决过程】

1.网上搜了下,找到对应的xsl了:

common.xsl

但是对于问题的解决没啥帮助。

2.找到其他人遇到类似问题:

[docbook-apps] Re: bibliodiv

但是无解。

3.看起来此警告信息是xslt抛出的,所以想办法去找ant的xslt当前用的是什么。

4.找到:

eclipsehelp – namespace problem, no template matches

也遇到Request for label of unexpected element的问题,但是无解。

5.后来更加网上的源码:

common/ labels.xsl

然后自己去找到了我本地的label.xsl,调用关系为:

webhelp.xsl -> xhtml/chunk.xsl -> docbook.xsl -> ../common/labels.xsl

其中有:

<xsl:template match="*" mode="label.markup">
  <xsl:param name="verbose" select="1"/>
  <xsl:if test="$verbose">
    <xsl:message>
      <xsl:text>Request for label of unexpected element: </xsl:text>
      <xsl:value-of select="local-name(.)"/>
    </xsl:message>
  </xsl:if>
</xsl:template>

此处,不知道为何bibliodiv会出现此警告。

6.然后网上搜label.markup找到了官网的解释:

Chapter 10. General customizations

看了解释大概明白了,label.markup就是用于给各种docbook内的元素去添加编号的。

所以,此处很明显是对于bibliodiv,没法实现编号,而如果对于参数verbose设置为1的话,所以才抛出此警告的。

7.看到了一个有点异常的事情:

bibliography在html和pdf的输出都是正常的,都可以被翻译为:参考书目

html中bibliography可以被翻译为 参考书目

pdf中bibliography可以被翻译为 参考书目

但是webhelp中bibliography没有被翻译:

webhelp 中bibliography没有被翻译为 参考书目

 

所以就又去找bibliography,然后在找到labels.xsl中的:

<xsl:template match="d:bibliography|d:glossary|
                     d:qandaset|d:index|d:setindex" mode="label.markup">
  <xsl:if test="@label">
    <xsl:value-of select="@label"/>
  </xsl:if>
</xsl:template>

好像是可以正常编号的,但是翻译的事情,暂时懒得理了。

但是可以去添加bibliodiv进去:

<xsl:template match="d:bibliography|d:glossary|
                     d:qandaset|d:index|d:setindex|d:bibliodiv" mode="label.markup">
  <xsl:if test="@label">
    <xsl:value-of select="@label"/>
  </xsl:if>
</xsl:template>

然后试试效果,结果是,竟然就可以解决问题,没有了上面的错误提示了,完整的log如下:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/language_summary/src
$ make webhelp
=============================== generating webhelp ==============================
ant webhelp
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\dev\books\language_summary\src\build.xml

validate:

clean:
   [delete] Deleting directory E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp
     [xslt] Processing E:\Dev_Root\docbook\dev\books\language_summary\src\language_summary.xml to E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp\null884607957
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.1\profiling\profile.xsl
     [xslt] Processing E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp\null884607957 to E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp\null1987721164
     [xslt] Loading stylesheet E:\Dev_Root\docbook\dev\ant\webhelp\xsl\webhelp_crl.xsl
     [xslt] language: en
     [xslt] Writing ../output/webhelp/content/ch01s01.html for sect1
     [xslt] Writing ../output/webhelp/content/ch01_lan_intro.html for chapter(ch01_lan_intro)
     [xslt] Writing ../output/webhelp/content/ch02s01.html for sect1
     [xslt] Writing ../output/webhelp/content/lan.python.html for sect1(lan.python)
     [xslt] Writing ../output/webhelp/content/ch02s03s01.html for sect2
     [xslt] Writing ../output/webhelp/content/ch02s03s02.html for sect2
     [xslt] Writing ../output/webhelp/content/ch02s03s03.html for sect2
     [xslt] Writing ../output/webhelp/content/ch02s03s04.html for sect2
     [xslt] Writing ../output/webhelp/content/lan.word_vba.html for sect1(lan.word_vba)
     [xslt] Writing ../output/webhelp/content/ch02s04s01.html for sect2
     [xslt] Writing ../output/webhelp/content/ch02s04s02.html for sect2
     [xslt] Writing ../output/webhelp/content/ch02s04s03.html for sect2
     [xslt] Writing ../output/webhelp/content/ch02s04s04.html for sect2
     [xslt] Writing ../output/webhelp/content/lan.excel_vba.html for sect1(lan.excel_vba)
     [xslt] Writing ../output/webhelp/content/ch02s05s01.html for sect2
     [xslt] Writing ../output/webhelp/content/lan.javascript.html for sect1(lan.javascript)
     [xslt] Writing ../output/webhelp/content/ch02s06s01.html for sect2
     [xslt] Writing ../output/webhelp/content/ch02s06s02s01.html for sect3
     [xslt] Writing ../output/webhelp/content/ch02s06s02s02.html for sect3
     [xslt] Writing ../output/webhelp/content/lan.php.crifanlib.html for sect2(lan.php.crifanlib)
     [xslt] Writing ../output/webhelp/content/lan.php.html for sect1(lan.php)
     [xslt] Writing ../output/webhelp/content/ch02s07s01.html for sect2
     [xslt] Writing ../output/webhelp/content/ch02s07s02.html for sect2
     [xslt] Writing ../output/webhelp/content/lan.linux_shell.html for sect1(lan.linux_shell)
     [xslt] Writing ../output/webhelp/content/win_bat_intro.html for sect2(win_bat_intro)
     [xslt] Writing ../output/webhelp/content/win_bat_learn_summary.html for sect2(win_bat_learn_summary)
     [xslt] Writing ../output/webhelp/content/win_bat_refer.html for sect2(win_bat_refer)
     [xslt] Writing ../output/webhelp/content/lan.windows_bat.html for sect1(lan.windows_bat)
     [xslt] Writing ../output/webhelp/content/ch02_script_lan.html for chapter(ch02_script_lan)
     [xslt] Writing ../output/webhelp/content/ch03s01.html for sect1
     [xslt] Writing ../output/webhelp/content/lan.csharp.html for sect1(lan.csharp)
     [xslt] Writing ../output/webhelp/content/ch03s03s01.html for sect2
     [xslt] Writing ../output/webhelp/content/lan.cpp.html for sect1(lan.cpp)
     [xslt] Writing ../output/webhelp/content/ch03_uppper_lan.html for chapter(ch03_uppper_lan)
     [xslt] Writing ../output/webhelp/content/ch04s01s01.html for sect2
     [xslt] Writing ../output/webhelp/content/lan.xml.html for sect1(lan.xml)
     [xslt] Writing ../output/webhelp/content/ch04s02s01.html for sect2
     [xslt] Writing ../output/webhelp/content/html_refer.html for sect2(html_refer)
     [xslt] Writing ../output/webhelp/content/lan.html.html for sect1(lan.html)
     [xslt] Writing ../output/webhelp/content/ch04_web_lan.html for chapter(ch04_web_lan)
     [xslt] Writing ../output/webhelp/content/reference.html for bibliography(reference)
     [xslt] Writing ../output/webhelp/content/index.html for book
     [xslt] Writing ../output/webhelp/index.html
     [xslt] Writing ../output/webhelp/content/search/l10n.js
     [copy] Copied 1 empty directory to 1 empty directory under E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp\content

index:
     [copy] Copying 1 file to E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp
     [copy] Copying 4 files to E:\Dev_Root\docbook\dev\books\language_summary\output\webhelp
     [echo] Indexing html files in ../output/webhelp/content
     [java] Stemming enabled
     [java] The created index files are located in ..\output\webhelp\content\search\.js
     [java] Indexed the contents in 1 seconds

webhelp:

BUILD SUCCESSFUL
Total time: 9 seconds

然后,此时,也稍微更加清楚了一点labels.xsl中的代码的逻辑。

labels.xsl中内部有很多个

<xsl:template match="xxx" mode="label.markup">

的代码,对应的就是去匹配docbook中的各种关键字xxx。

但是,如果对于xxx中所有的关键字都查找了一遍,还没有包括对应的关键字的话,那么则会调用最顶端的那个:

<xsl:template match="*" mode="label.markup">

然后抛出对应的警告:“Request for label of unexpected element: ”

所以,此时问题很清楚了,之前就是其中没有包含对应的bibliodiv这个关键字,导致最后抛出此警告的,所以添上之后,就没了此警告了。

8.虽然解决了问题,但是还是需要把刚才的改动提取出来,而不要影响到默认的docbook-xsl-ns-1.77.1中的配置。

所以,就去把原先对于labels.xsl的改动取消,然后去自己的xsl配置文件webhelp_crl.xsl中的最后的位置,添加上:

<!-- remove warning: Request for label of unexpected element: bibliodiv -->
<xsl:template match="d:bibliodiv" mode="label.markup">
  <xsl:if test="@label">
    <xsl:value-of select="@label"/>
  </xsl:if>
</xsl:template>

由此,即可解决问题,且保持不去改动docbook-xsl-ns-1.77.1原有的配置。

 

【总结】

上面之所以会有警告:

Request for label of unexpected element:

出现,是由于相关的xsl配置中,对于给各种docbook中的元素添加编号,使用的是label.markup这个mode,而对应的

docbook-xsl-ns-1.77.1\common\labels.xsl

中,没有包括对于bibliodiv这个关键字,即没有支持bibliodiv,所以才抛出警告的。

解决办法是,手动添加上对应的配置:

<!-- remove warning: Request for label of unexpected element: bibliodiv -->
<xsl:template match="d:bibliodiv" mode="label.markup">
  <xsl:if test="@label">
    <xsl:value-of select="@label"/>
  </xsl:if>
</xsl:template>

即可解决此警告。

 

另外,关于webhelp中,bibliography没有被翻译为“参考书目”的问题,等有空再解决吧。

转载请注明:在路上 » 【已解决】用ant编译docbook生成webhelp过程中出错:Request for label of unexpected element: bibliodiv

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.189 seconds, using 22.34MB memory