xsl-list
[Top] [All Lists]

RE: Problem in calling external java function

2004-09-20 05:20:43
Hi,

  Well , i have figured out the problem. 

 The command :

java org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -out out.xml

 first searches for the java class along with package name ( tester.xyz ) in
the same directory where the xsl and xml are.
If class is not found in the relative path it looks in the classpath
specified in the command 

for example: java -cp "C:" org.apache.xalan.xslt.Process -in test.xml -xsl
test.xsl -out out.xml 

and if still not found it looks in the system classpath (Environment
variable if any).

In my case wrong file was being picked ( i had a class xyz placed in the
directory tester in the same directory as my xml and xsl ), While i was
updating any changes to class xyz in some other location.

Well I know it has been a goof-up, but this can act as a lesson to all of
us. RIGHT?

Thanx for your answers and cooperation.

Regards
Manpreet


-----Original Message-----
From: Manpreet Singh [mailto:singhm(_at_)quark(_dot_)co(_dot_)in]
Sent: Monday, September 20, 2004 4:24 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Problem in calling external java function
Importance: High


Hi,
   The following is the xslt code calling a java class:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";  xmlns:test="C://tester"
exclude-result-prefixes="test">
        <xsl:template match="/">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="b">
                <xsl:variable name="test1"
select="test:xyz.new('A;B;C',';')"/>
                <abc>
                        <xsl:value-of select="test:getNextToken($test1)"/>
                </abc>
        </xsl:template>
</xsl:stylesheet>


The following is the code for the class being called:

import java.util.StringTokenizer;

public class xyz {

  private StringTokenizer tokenizer;

  public CreateMultipleTargetInstance( String specimen, String token ) {
    tokenizer = new StringTokenizer ( specimen, token );
  }

  public String getNextToken() {
    if ( tokenizer.hasMoreTokens() ) {
      return tokenizer.nextToken();
    }
    else {
      return "";
    }
  }
}

When i call this class using the above xslt Through command prompt using the
following command:

java org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -out out.xml

i get the following error:

file:/C:abc.xsl;
 Line #9; Column #-1; XSLT Error (javax.xml.transform.TransformerException):
java.lang.NoSuchMethodException: For extension function, could not find
constructor
 tester.CreateMultipleTargetInstance([ExpressionContext,] #STRING, #STRING).


The xslt is supposed to return me the first string before ";" i.e A.

...........ANYONE?

Regards
Manpreet

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--



<Prev in Thread] Current Thread [Next in Thread>