在XSLT中调用Java函数

时间:2014-08-07 08:17:02

标签: java xslt xalan

我有在xslt中使用java调用方法的案例研究。

以下是我的XSLT: -

 <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:test="java:com.package_name.com.Test">
<xsl:output method="xml" omit-xml-declaration="yes"/>
 <xsl:template match="/" >
    <xsl:for-each select="info/data">
    <xsl:variable name="VALUE" select="number"/>
    <int>
         <xsl:value-of select="test:calculate($VALUE)"/>
    </int>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

Java函数:

public static String calculate(int n) {
      String message="The NUmber is Right";
      String error="Wrongggg";
    if (n == 5) 
       return (message);
    else
       return (error);
  }

我收到如下错误消息:

Type:INTEGER:5
                                    Text:CHARACTER:Transformation failure when processing Stylesheet deployed:./Test.xsl
javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: The XSL processor reported a possibly fatal error.
Message: java.lang.IllegalArgumentException: name
    at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1017)
    at com.ibm.xsl.exmlt.StylesheetCache.preprocessStylesheet(StylesheetCache.java:763)
    at com.ibm.xsl.exmlt.StylesheetCache.getPreprocessedStylesheet(StylesheetCache.java:686)
    at com.ibm.xsl.exmlt.StylesheetSelector.getTransformer(StylesheetSelector.java:372)
    at com.ibm.xsl.exmlt.StylesheetSelector.performSelection(StylesheetSelector.java:681)
    at com.ibm.xsl.exmlt.EnhancedXMLTransform.transformDocument(EnhancedXMLTransform.java:615)
    at com.ibm.xsl.mqsi.XMLTransformData.transformData(XMLTransformData.java:555)
    at com.ibm.xsl.mqsi.XMLTransformNode.evaluate(XMLTransformNode.java:965)
    at com.ibm.broker.plugin.MbNode.evaluate(MbNode.java:1480)
Caused by: javax.xml.transform.TransformerException: The XSL processor reported a possibly fatal error.
Message: java.lang.IllegalArgumentException: name
    at com.ibm.xsl.exmlt.StylesheetSelector.fatalError(StylesheetSelector.java:1725)
    at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1009)

任何人都可以纠正我如何在XSLT中调用java函数。 提前谢谢。

此致 罗希特夏尔。

0 个答案:

没有答案