on 02-17-2014 8:51 AM
Dear SCN users,
I Just tried parameterised XSLT mapping By calling a JAva class in XSLT.
After implementing,Java class is working fine calling the parameter from operation mapping.
But getting the error in XSLT mapping as below.
Below is my XSLT code.
Please help me on this and if there is anyother effiicient way of doing parameterised XSLT mapping let me know,
Hello,
I think u are not calling ur java class properly? It should be like:
xmlns:javamap="java:<PackaeName>.<ClassName>"
or
xmlns:javamap="<PackaeName>.<ClassName>"
http://scn.sap.com/docs/DOC-46751
BTW, can u paste ur input xml file which you are using to test above xslt?
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Amit,
I used default package,so I defined like"xmlns:xslsaver="java:default.dyanmic".
Is this wrong ?,If so please let me know what I should define here.
After selecting XML tookit I am getting the below error.
Please help on this issue Amit
And below is the Test XML I used
For date field I am passing value using parameter.
Hello,
Did u test ur java mapping code?
Open ur OM -> go to test tab -> and check if ur java mapping is properly returning output?
BTW, u have to check "use xml toolkit" option in OM. Paste ur class error also.
Note - i tried replicating ur scenario and it's perfectly working fine in my system
Thanks
Amit Srivastava
Hello,
IMO, the problem is that u are not calling java class properly.
U can use below code (reading date parameter from mapping, i guess this is want u want?) and check if it's working for u?
package com.ima.po;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Map;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.InputParameters;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
/**
*
*/
public class JavaCode extends AbstractTransformation{
public final static String namespace = "http://pi";
public final static String Date = "Date";
public void transform(TransformationInput in, TransformationOutput output) throws StreamTransformationException
{
DynamicConfiguration dc = in.getDynamicConfiguration();
InputParameters parameters = in.getInputParameters();
// add the seperate values
getTrace().addInfo("Date " + parameters.getString("Date"));
DynamicConfigurationKey userKey = DynamicConfigurationKey.create(namespace, Date);
dc.put(userKey, parameters.getString("Date"));
//copy the original content
try{
InputStream instream = in.getInputPayload().getInputStream();
OutputStream outstream = output.getOutputPayload().getOutputStream();
byte[] buf = new byte[1024];
int numRead=0;
while((numRead=instream.read(buf)) != -1){
outstream.write(buf, 0, numRead);
}
outstream.flush();
}catch(IOException ioe){
throw new StreamTransformationException(ioe.getMessage(),ioe);
}
}
public static String getValue(Map map, String key){
try{
DynamicConfiguration dc = (DynamicConfiguration)map.get("DynamicConfiguration");
DynamicConfigurationKey keyConfig = DynamicConfigurationKey.create(namespace, key);
return dc.get(keyConfig);
}catch(Exception e){
return "Error fetching key "+ key + " because: " +e.getMessage();
}
}
}
XSLT code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:javamap="java:com.ima.po.JavaCode" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="inputparam"/>
<xsl:template match="/">
<Date>
<xsl:value-of select="javamap:getValue($inputparam, 'Date')"/>
</Date>
</xsl:template>
</xsl:stylesheet>
OM output (make sure u are calling JM first and then XSLT):
Thanks
Amit Srivastava
Hello Amit,
My requirement is Name and Id will be normal parameter.
And Date alone passed as an parameter from ID.
can you please send the jar files which you used to my id-raghuin10@gmail.com
Hello,
I couldn't able to attach zip files in this thread (i think there is a way to do that but unfortunately i don't know)
So i would suggest u to copy below attached java code in ur (java) project inside NWDS (just make sure that u use "com.po" as the package name and "JavCode" as the class name) and then create ur zip file and import the same in PI.
In addition to that, i have also attached the xslt file, so u can just rename it to .xsl, zip the same and import it inside PI.
Under OM -> use java and xslt in sequence + check use SAP xml toolkit option and then test
Thanks
Amit Srivastava
Hello Raghuraman,
Please have a look at the following thread:
https://scn.sap.com/thread/1762902
Select XMLTOOLKIT option in Operation mapping and execute it. This should solve your issue.
Regards,
Ankit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raghu,
Plz check below:
Regards
GB
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.