cancel
Showing results for 
Search instead for 
Did you mean: 

Paramatereized XSLT mapping

former_member186851
Active Contributor
0 Kudos

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,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

former_member186851
Active Contributor
0 Kudos

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.

former_member184720
Active Contributor
0 Kudos

Hi Raghu - I'm not sure if it is typo or you java class name itself is really "dyanmic"(dynamic)

Former Member
0 Kudos

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

former_member186851
Active Contributor
0 Kudos

Hello Amit,

Java code is fine..Getting error while calling java class from XSLT.

Can you guide me where I am wrong..And you tried both java and XSLT?..

former_member186851
Active Contributor
0 Kudos

Hello Hareesh,

The Class name is dyanmic ..

gagandeep_batra
Active Contributor
0 Kudos

Hi Raghu,

Can you check the class name whather it is "dyanmic" or "Dyanmic" or "dynamic" check case and spelling also



Regards

GB

former_member186851
Active Contributor
0 Kudos

Hello Gaga,

It is dyanmic.

What else could be the problem?.

Former Member
0 Kudos

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

former_member186851
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

former_member186851
Active Contributor
0 Kudos

Hello Amit,

Thanks a lot,

It is working fine,I modified XSLT as per my requirement and it is perfect.:)

Answers (2)

Answers (2)

ankit_srivastava3
Participant
0 Kudos

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

former_member186851
Active Contributor
0 Kudos

Hello Ankit.

I just did it,Getting error in calling class

ankit_srivastava3
Participant
0 Kudos

Hello Raghuram,

Define <xsl:param name ="inputparam" /> before <xsl:template match = "/"> in your xslt and then check (as like a global variable).

Regards,

Ankit Srivastava

former_member186851
Active Contributor
0 Kudos

Hello Ankit,

If I do so,I am getting "no program found" if I try to add my XSL in mapping program

gagandeep_batra
Active Contributor
0 Kudos
former_member186851
Active Contributor
0 Kudos

Hello Gaga,

Thanks a lot for sharing the blog

I followed the same blog.