Topic
  • 3 replies
  • Latest Post - ‏2011-03-07T08:00:43Z by SystemAdmin
ManiGRS
ManiGRS
2 Posts

Pinned topic exception while calling java method from XSL

‏2011-03-04T23:44:39Z |
I'm trying to call java method from XSL and getting the following error. Code snippet is given below. I'm trying to invoke my test class in RAD7. Earliest reply is highly appreciated.

Error

(Location of error unknown)java.lang.NoSuchMethodException: For extension function, could not find method org.apache.xml.utils.NodeVector.getDetails(ExpressionContext, ).

Test Class

TransformerFactory tFactory = TransformerFactory.newInstance();
Templates translet = tFactory.newTemplates(new StreamSource(xslFile));
Transformer transformer = translet.newTransformer();
transformer.transform(inStreamSource,outStreamSource);

Java code

DataService.java

public static String getDetails(String requestID){
String tmpString = null;
tmpString = "040112345698";
return tmpString;
}

XSL Code

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:trans="http://xml.apache.org/xalan/java/java.lang.Math"
xmlns:dataTrans="http://xml.apache.org/xalan/java/com.transform.util.DataService"
exclude-result-prefixes="trans dataTrans">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
..
..
..
<xsl:variable name="requestID" select="Order/Misc"/>
<detail>
<xsl:value-of select="dataTrans:getDetails($requestID)"/>
</detail>

I'm able to invoke the methods in java.lang.Math. However i'm not able to do while using the DataService class.
Updated on 2011-03-07T08:00:43Z at 2011-03-07T08:00:43Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1830 Posts

    Re: exception while calling java method from XSL

    ‏2011-03-05T13:12:09Z  
    I can only say generally, independent of rad7. And this is the single most needed correction.
    
    <xsl:stylesheet xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" version=
    "1.0" xmlns:trans=
    "http://xml.apache.org/xalan/java/java.lang.Math" xmlns:dataTrans=
    "xalan://com.transform.util.DataService" exclude-result-prefixes=
    "trans dataTrans">
    
  • ManiGRS
    ManiGRS
    2 Posts

    Re: exception while calling java method from XSL

    ‏2011-03-07T00:14:57Z  
    I can only say generally, independent of rad7. And this is the single most needed correction.
    <pre class="jive-pre"> <xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" version= "1.0" xmlns:trans= "http://xml.apache.org/xalan/java/java.lang.Math" xmlns:dataTrans= "xalan://com.transform.util.DataService" exclude-result-prefixes= "trans dataTrans"> </pre>
    Suji, thanks for your response.
    I tried your suggestion and also by declaring the namespace for xalan as
    xmlns:xalan="http://xml.apache.org/xalan" and declaring the java class as
    xalan://com.... but still getting the same error.
  • SystemAdmin
    SystemAdmin
    1830 Posts

    Re: exception while calling java method from XSL

    ‏2011-03-07T08:00:43Z  
    • ManiGRS
    • ‏2011-03-07T00:14:57Z
    Suji, thanks for your response.
    I tried your suggestion and also by declaring the namespace for xalan as
    xmlns:xalan="http://xml.apache.org/xalan" and declaring the java class as
    xalan://com.... but still getting the same error.
    [0] Just for precision, if there is no need to declare xmlns:xalan=... like what you said in the followup. You only need xmlns:dataTrans as shown in my response, and use it in the templates. That's all you need to do. Whereas xmlns:trans is, I suppose, for your side-test and I left it as such for continuity.

    [1] If the proper declaration of xmlns:dataTrans does not by itself sufficient to rectify the problem, it means the set up of classpath and the class file may not be done correctly. That would not be the concern of the construction for the use of xalan extension.

    [1.1] You have to import the DataService class into the your main java file.
    
    
    
    import com.transform.util.DataService;
    

    [1.2] In the DataService.java, you have sure to precise the package, like this.
    
    
    
    package com.transform.util;   
    //etc...
    

    [1.3] Then the placement of DataService.class should be in a directory structure like x/com/transform/util/DataService.class where the parent directory x be reachable by classpath.

    That's about it and you see those settings are the same as whatever java programming and are not specific to the use of xalan extension.