Showing posts with label XSLT. Show all posts
Showing posts with label XSLT. Show all posts

Tuesday, January 6, 2009

ora:get-Content-as-string

Hi,
In my previous post i wrote about a custom xpath function to convert a string representation of XML to a XML.
In this post lets see a function which the reverse of this.
This function can be used to convert a XML to a string.
for ex:
xsl:value-of select ="orcl:get-content-as-string(/nso:Booklist/nso:Bookdesc:desc")

Happy Learning






ora:parseEscapedXML

Hi,
Oracle provides a custom xpath function,which can be used to convert a string representation of a XML input to a XML ,i.e the input which you are getting is a proper XML input but has been represented as a string.
The function is ora:parseEscapedXML(String).
One workaround is when we directly use this function in the XSLT,by default it does value-of,so the value of the XML input is selected.
Ex:
When we call this function and give the output of this function to a out variable the source looks like
xsl:value-of select="orcl:parseEscapedXML(/ns0:Message/ns0:msgData)"/

So the value of the variable msgData is passed instead of the XML.

This can be overcome by
1)Create a local XSLT variable pass the output of your function to this variable.
2)Use Copy-of and copy the variable to the required output variable
For Ex:
Replace the whole of
xsl:value-of select="orcl:parseEscapedXML(/ns0:Message/ns0:msgData)"/
with
xsl:variable name="parsedMsgData" select="orcl:parseEscapedXML(/ns0:Message/ns0:msgData)"/>

xsl:copy-of select="$parsedMsgData"/


Happy Learning

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