Use XSLT 2.0 functions in Eclipse WTP Helios

1 篇文章 0 订阅
1 篇文章 0 订阅

For a simple xml file (onega.xml)

<?xml version="1.0" encoding="UTF-8"?>
<numbers>
  <val>
  <num>18</num>
  <num>1</num>
  <num>40</num>
  </val>
</numbers>

I am using the following xslt file (onega.xsl) to get the sum of all "num" elements

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
    <xsl:template match="/numbers">
        <sum>
            <xsl:value-of select="fn:sum(val/num[number(.)=number(.)])" />
        </sum>
    </xsl:template>
</xsl:stylesheet>

 

Open onega.xsl and onega.xml in Eclipse WTP 3.6.2 (helios), activate onega.xsl, select menu "Run" -> "Run as" -> "XSL Transformation"

 

select "Window" -> "Preferences" -> XML -> XSL -> Java Processors, there are two installed java XSLT processors:

    JRE Instance Default

    Xalan 2.7.1

 

"JRE Instance Default" is checked by default, and give me the following error:

10:15:10,953 INFO  [main] Main  - javax.xml.transform.TransformerFactory=null
10:15:10,956 INFO  [main] Main  - java.endorsed.dirs=/usr/lib/jvm/java-6-openjdk/jre/lib/endorsed
10:15:10,962 INFO  [main] Main  - launchFile: /d4/workspace/jboss/.metadata/.plugins/org.eclipse.wst.xsl.jaxp.launching/launch/launch.xml
10:15:11,090 ERROR [main] JAXPSAXProcessorInvoker  - The first argument to the non-static Java function 'sum' is not a valid object reference.
10:15:11,092 ERROR [main] JAXPSAXProcessorInvoker  - Could not compile stylesheet
javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:843)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:632)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformerHandler(TransformerFactoryImpl.java:918)
    at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.addStylesheet(JAXPSAXProcessorInvoker.java:136)
    at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.addStylesheet(JAXPSAXProcessorInvoker.java:127)
    at org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition.addStyleSheet(PipelineDefinition.java:161)
    at org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition.configure(PipelineDefinition.java:152)
    at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.Main.main(Main.java:72)
10:15:11,094 FATAL [main] Main  - Error with stylesheet: file:/d4/workspace/jboss/tutorialclient/onega.xsl
org.eclipse.wst.xsl.jaxp.debug.invoker.internal.ConfigurationException: Error with stylesheet: file:/d4/workspace/jboss/tutorialclient/onega.xsl
    at org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition.addStyleSheet(PipelineDefinition.java:163)
    at org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition.configure(PipelineDefinition.java:152)
    at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.Main.main(Main.java:72)

 

Switch to "Xalan 2.7.1", I still get the following error

 

10:07:56,312 INFO  [main] Main  - javax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl
10:07:56,315 INFO  [main] Main  - java.endorsed.dirs=/d4/workspace/jboss/.metadata/.plugins/org.eclipse.wst.xsl.jaxp.launching/endorsed
10:07:56,320 INFO  [main] Main  - launchFile: /d4/workspace/jboss/.metadata/.plugins/org.eclipse.wst.xsl.jaxp.launching/launch/launch.xml
10:07:56,813 INFO  [main] JAXPSAXProcessorInvoker  - Transforming...
(Location of error unknown)java.lang.NoSuchMethodException: For extension function, could not find method org.apache.xml.utils.NodeVector.sum([ExpressionContext,] ).
10:07:56,830 INFO  [main] JAXPSAXProcessorInvoker  - Done.

 

solution: download saxonhe9-3-0-4j.zip , extract saxon9he.jar and add this jar file to  "Window" -> "Preferences" -> XML -> XSL -> Java Processors -> "Installed Java XSLT Processors", with name "saxon", Type "Saxon (XSLT 2.0)". Select saxon and now my xsl file works properly.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值