Thursday, December 11, 2008

User Defined Functions in XSLT

Hi,

In this post lets learn on the User Defined Functions Option in the Transform activity in Jdeveloper,which lets you use your own function in the transform activity.

There are mainly two steps:

1)Write a class with a static method to implement the logic you want.
2)Register the xml in Jdeveloper,and add the class in Jdev classpath

To illustrate more on it lets take an example of adding two numbers.

1)The first step is to create a class with static method implementing the logic .

Take a example of adding two numbers,with a class called as TestingExtensionFunctions

The static method is as below:

package oracle.testing;
public class TestingExtensionFunctions
{
public static int add(int a,int b)
{
return a+b;
}
}

2)Next,Create an XML file detailing the extension functions which we will give in the JDeveloper "User Defined Extension Functions Config File" field of the XSL Map preferences (Tools->Preferences->XSL Map). This will list the functions in the User Defined Extension Functions section of the XSL Map component palette so you can drag and drop it into the XSLT at design time.

The extension functions XML looks like this :



After adding this xml file make the java class that implements the functions,part of JDeveloper classpath. This can be done by creating a jar file in \jdev\extensions directory.

Create the jar file in the Jdev_home\jdev\extensions directory.
One important thing is to add the extension.xml file to the jar file.
This can be done by Opening the jar file using Winzip,and add the file.
The extension.xml file should be placed in the Meta-inf Folder.

The contents of the extensions.xml file is like the following



Start using the function
If the XSL generated by the XSL Mapper is to be used by the Oracle BPEL engine, please add the jar file to the application server classpath.For OC4J copy the jar file to \j2ee\home\applib.

Happy Learning

Regards
Ashwini





4 comments:

Praveena said...

Hi Ashwini,

I am working User Defined Extension Functions to be used in ESB. I have implemented the java class file, prepared the xml file and uploaded the jar file j2ee.home.applib directory, it is working iin Windows environement, but when I deploy the same in Unix, is is giving me error "XML-22043: (Error) Extension function error: Method not found 'debug'". debug is m method.

Could you please tell me if I am missing anything?

Ashwini said...

Hi Praveena,

In the extensions.xml,what encoding style have you used.

Regards
Ashwini

Ebrahim Badusha said...

Hi,

I too have the same issue in my UNIX environment. The application is working fine in Windows.

Thanks
Ebrahim Badusha

Ebrahim Badusha said...

@Ashwini,
Could you please tell where i can find extensions.xml?
Appreciate your help.