Chitta,



So now I need to call those methods to the Java class from XSL with some parameters where the
methods will receive the parameters from XSL, perform
all the operations mentioned in the method body and
then will return some value again to the calling
method in XSL to which I can display.


I wish there was time to explain everyting to you in detail but if I understood correctly what you want to do I 'll point you to an example and help you complete that.

If you go at http://xml.apache.org/xalan-j/extensions.html and scroll down where it says "Formatting a date".

Copy-paste and compile it. Then in order to be sure that everything works I would suggest you try first transforming the document from the command line. (by the way you have to write an XML file with some trivial structure and a date element so as this example to work) Later in this page:

http://xml.apache.org/xalan-j/extensions.html#format-date-stylesheet

there is the styleshhet that would do the job for you (in this case convert the date). The important bits are:

...
xmlns:java="http://xml.apache.org/xalan/java";
exclude-result-prefixes="java">

and

<xsl:variable name="date" select="java:IntDate.getDate($year, $month, $day)"/>


This assumes that you have the directory where IntDate.class lies in your classpath. Make sure you read this:


http://xml.apache.org/xalan-j/extensions.html#ext-func-calls

(in general make sure you read this page very carefully I think from this page you can manage what you want)


Now (since you are saying you are using XSL in JSP) I prefer putting my extensions functions in JAR file. So what you can do to test with the current example:


jar -cf myExtensions.jar IntDate.class

(you can do all sorts of things like have packages there etc. this is just a simple-dirty example)

Change the stylesheet to read:

...
xmlns:myExtensions="MyExtensions"

and

<xsl:variable name="date" select="myExtensions:IntDate.getDate($year, $month, $day)"/>

Everything should work again (try from the command line first - make sure you add the jar in your classpath). If this is the case put the jar file in the lib directory of your webapp, write the code that transforms the XML (since you said you did that before you probably knw how to and also are aware of the problems that may occur with the bundled version of xalan with JDK : see http://xml.apache.org/xalan-j/faq.html#faq-N100CB and in general this FAQ page is very helpful)

Hoep this helps for a start.

Manolis







Reply via email to