我使用Ant 1.8在文件夾中的文檔上運行一些XSLT。 Ant使用Xalan來處理XSLT。作業運行正常,我得到了一組對應於輸入文件的轉換輸出文件。無法在Javascript或Jython中使用Ant創建XSLT擴展
問題是,當試圖用JavaScript或Jython函數擴展XSL來處理一些棘手的字符串時。無論是Javascript還是Jython都可以,無論哪一個首先運行,但現在都不是。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:jython-extension="http://www.jython.org/"
xmlns:lxslt="http://xml.apache.org/xslt"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="lxslt xalan"
xmlns:gotofritz="GotoFritz">
<xalan:component prefix="gotofritz" functions="test">
<xalan:script lang="javascript">
function test(){
return '********* JS WORKS *******';
}
</xalan:script>
</xalan:component>
<lxslt:component prefix="jython-extension" functions="test">
<lxslt:script lang="jpython">
def test():
return "**** JYTHON WORKS ****"
</lxslt:script>
</lxslt:component>
<xsl:template match="/">
<xsl:value-of select="gotofritz:test()"/>
<xsl:value-of select="jython-extension:test()"/>
</xsl:template>
</xsl:stylesheet>
我已經下載bsf.jar和javascript.har,以及最新的Xalan罐子,搬到他們到/ usr /共享/螞蟻/ lib目錄 - 我在OS X
的javscript失敗,錯誤!找不到類'GotoFritz'。「和「錯誤!找不到外部方法'GotoFritz.test'(必須公開)」。
Jython不合格 警告!無法解析調用函數'http://www.jython.org/:test'。
java.lang.VerifyError: (class: test, method: template$dot$3 signature: (Lcom/sun/org/apache/xalan/internal/xsltc/DOM;Lcom/sun/org/apache/xml/internal/dtm/DTMAxisIterator;Lcom/sun/org/apache/xml/internal/serializer/SerializationHandler;I)V) Expecting to find integer on stack
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.getTransletInstance(TemplatesImpl.java:353)
at com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.newTransformer(TemplatesImpl.java:382)
at org.apache.tools.ant.taskdefs.optional.TraXLiaison.createTransformer(TraXLiaison.java:319)
at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:177)
at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:852)
at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:388)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
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:809)
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)
它看起來對我說的Xalan是標本兼治的擴展如Java,而不是使用BSF。有任何想法嗎?提前致謝。
這看起來不錯 - 我會測試它並回復你,謝謝! – gotofritz 2013-04-10 08:17:36