【问题】
docbook环境中,已经实现了用ant编译webhelp:
然后接着打算把原先默认的xsl等配置文件,都替换为自己想要的。
即移至原先的webhelp的默认的环境,整合到我的原先的docbook的编译系统中。
但是在刚开始,刚去把一个xsl中include/import另一个xsl的路径,从相对路径:
<xsl:include href="webhelp-common.xsl"/>
改为绝对路径:
<xsl:include href="E:/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp/xsl/webhelp-common.xsl"/>
结果就出现错误了:
Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/arm_vs_mips/src $ ant webhelp --execdebug exec "/cygdrive/d/Program Files/Java/jre7/bin/java" -classpath "E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib/ant-launcher.jar" -Dant.home="E:/dev_install_root/apache_ant/apache-ant-1.8.4" -Dant.library.dir="E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib" -Dcygwin.user.home="E:/dev_install_root/cygwin/home/Administrator" org.apache.tools.ant.launch.Launcher -cp ".;D:/Program Files/Java/jre7/lib" "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\arm_vs_mips\src\build.xml validate: clean: [delete] Deleting directory E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp chunk: [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\arm_vs_mips.xml to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1163544719 [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1163544719 to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1928718928 [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp.xsl [xslt] E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp.xsl:33: Error! Failure reading E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp-common.xsl Cause: java.io.EOFException: no more input [xslt] Failed to process E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1163544719 BUILD FAILED E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml:63: javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected. at com.icl.saxon.PreparedStyleSheet.prepare(PreparedStyleSheet.java:134) at com.icl.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:120) at org.apache.tools.ant.taskdefs.optional.TraXLiaison.readTemplates(TraXLiaison.java:300) at org.apache.tools.ant.taskdefs.optional.TraXLiaison.createTransformer(TraXLiaison.java:317) at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:178) at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:853) at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:389) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:392) at org.apache.tools.ant.Target.performTasks(Target.java:413) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) at org.apache.tools.ant.Project.executeTarget(Project.java:1368) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1251) at org.apache.tools.ant.Main.runBuild(Main.java:811) at org.apache.tools.ant.Main.startAnt(Main.java:217) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) Total time: 2 seconds
即:
[xslt] xxx.xsl:33: Error! Failure reading yyy.xsl Cause: java.io.EOFException: no more input
和
xxx.xml:63: javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected.
的错误。
【解决过程】
1.网上找了很多帖子,但是好像都没有什么具体的解决办法。很多看不太懂其解释。
2.后来自己也折腾过N种,包括尝试了路径的其他几种写法:
cygwin的:
<xsl:include href="/cygdrive/e/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp/xsl/webhelp-common.xsl"/>
Unix/Linux和Windows都可以识别的:
<xsl:include href="E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp-common.xsl"/>
结果都是无法识别。
3.最后的最后,还是自己无意间把地址改为:
<xsl:include href="file:///E:/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp/xsl/webhelp-common.xsl"/>
结果就可以正常编译了:
Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/arm_vs_mips/src $ ant webhelp --execdebug exec "/cygdrive/d/Program Files/Java/jre7/bin/java" -classpath "E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib/ant-launcher.jar" -Dant.home="E:/dev_install_root/apache_ant/apache-ant-1.8.4" -Dant.library.dir="E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib" -Dcygwin.user.home="E:/dev_install_root/cygwin/home/Administrator" org.apache.tools.ant.launch.Launcher -cp ".;D:/Program Files/Java/jre7/lib" "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\arm_vs_mips\src\build.xml validate: clean: [delete] Deleting directory E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp chunk: [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\arm_vs_mips.xml to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1028983442 [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1028983442 to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null813495879 [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp.xsl [xslt] language: zh [xslt] Writing ../output/webhelp/content/glossary.html for glossary(glossary) [xslt] Writing ../output/webhelp/content/ch01s01.html for sect1 [xslt] Writing ../output/webhelp/content/ch01s02.html for sect1 [xslt] Writing ../output/webhelp/content/ch01_reduced_instruction_set.html for chapter(ch01_reduced_instruction_set) [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] Copying 1 file to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\content index: [copy] Copying 2 files to E:\Dev_Root\docbook\dev\books\arm_vs_mips\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] Delay = 322 milliseconds webhelp: BUILD SUCCESSFUL Total time: 4 seconds
4.后来经过尝试,发现
(1)windows的路径加上file:///,即这样的地址:
<xsl:include href="file:///E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp-common.xsl"/>
也是可以正常编译的。
(2)而cygwin加上file://的前缀:
<xsl:include href="file:///cygdrive/e/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp/xsl/webhelp-common.xsl"/>
是不可以的,无法正常编译的。
5.然后就去查找相关资料,找到权威解释:
的语法是:
<xsl:include href="URI"/>
而对应的URI,是之前就有所了解,但是没有完全去搞懂的。
然后就去专门再次查找资料:
才知道,原来此处的URI,对于本地文件,要么是相对路径,要么是以file:///开头的绝对路径。
6.然后又参考:XSLT – URI format
知道了,正常的情况下,xsl:include中,所支持的地址只有三种:
(1)相对路径:比如上面的webhelp-common.xsl,表示当前文件夹下面的webhelp-common.xsl文件。
(2)绝对路径(本地文件带file:///的前缀):比如 file:///E:/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp/xsl/webhelp-common.xsl
(3)URL:网络地址,以http://开头的那种,比如 http://docbook.org/ns/docbook
【总结】
但是很奇怪,为何在xsl:include中的地址,之前写成了不带file:///前缀的:
E:/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp/xsl/webhelp-common.xsl
为何也可以被xsltproc所支持?
然后查了查xsltproc的官网和其他一些地方,也还是没有找到完全有效的解释。
只能猜测是,xsltproc在处理stylesheet过程中,遇到xsl:include时,对于herf后面的值,是可以支持不带file:///的,自动可以识别为本地,当前电脑上的文件,所以是可以正常include或import对应的xsl文件的。
但是对于saxon这个xslt,其遵循了xsl:include严格的语法,对于不带file:///的本地绝对路径,这个是不符合URI的语法的,所以无法正常识别,所以就无法导入对应的xsl文件,此处才会报错的了。
如果有人找到更加确切和权威的解释,希望告知一下,谢谢。
【后记】
1. 关于windows中文件对应的URI,这里:
Specifying a drive in an URI under Windows
中也有解释,即加上对应的file:///。
2.截至目前,Specifying a drive in an URI under Windows中讨论算是最清晰和权威的解释了。
其也贴出了对于对应的 file的uri的spec,
而目前的理解,也是对的:
常见的,正确的写法是:
Windows:file:///c:/windows/example.ini
Unix/Linux:file:///path/to/file.txt
URL:http://docbook.org/ns/docbook
更详细的阐述,等有空有空再整理吧.
转载请注明:在路上 » 【已解决】docbook中,用ant使用saxon编译webhelp出错:Cause: java.io.EOFException: no more input … javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected