cancel
Showing results for 
Search instead for 
Did you mean: 

Problems faced in xslt mapping

Former Member
0 Kudos

Hi Experts,


I have one requirement. I have one Idoc to xml scenario in message mapping. The requirement is the target xml contains some nodes along with their type names.

For example


<ABC>
<XYZ xsi:type="ase:ABCDEF">
<EFG>
<PQR xsi:type="ase:DDFGY">
  <MNBV>333</MNBV>
  <JHGF>666</BGFD>
  </PQR>
</EFG>
</XYZ>
</ABC>

Presently I can only create the xml along with the nodes, but the xsi:type is not getting created.
I need to include the types to the nodes <XYZ> and <PQR> by xslt mapping.

Can you please suggest how can i include the typenames beside the required nodes?

Thanks & Regards,

Treya


Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks a lot for all of your suggestions. They were really helpful. Specially the solution provided by Nabendu helped me solve my problem.

Regards,

Treya

RaghuVamseedhar
Active Contributor
0 Kudos

Treya,

<XYZ xsi:type="ase:ABCDEF">

This is not well-formed XML. Element/Attribute names can not have :. GraphicalMapping/XSLT can not create not well-formed XML.

You can create graphical mapping for <XYZ xsi__type="ase:ABCDEF">

Then use Java Mapping (after graphical map) to replace xsi__type with xsi:type


package javaapplication1;

import java.io.*;

import com.sap.aii.mapping.api.*;

public class NewClass1 {

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {

        try {

            InputStream inputstream = transformationInput.getInputPayload().getInputStream();

            OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

            // Copy Input content to Output content 

            byte[] b = new byte[inputstream.available()];

            inputstream.read(b);

            String input = new String(b);

            input = input.replaceAll("xsi__type", "xsi:type");

            outputstream.write(input.getBytes());

        } catch (Exception exception) {

            throw new StreamTransformationException(exception.toString());

        }

    }

}

nabendu_sen
Active Contributor
0 Kudos
maheswarareddykonda
Active Contributor
0 Kudos

Hi Treya,

instead of going to XSLT mapping, i can suggest you to go for Graphical only..and try to create structure for target as what ever fields you want to send type name, create structure as same like that.

all you have to do is just add an argument for particular fields while you create data type.

and make sure argument name would be type

then in mapping level you just map with constant or map with source filed if u are getting type from source structure,

i hope this is easy way to develop.

let me know if u stuck.

BR,

Maheswarareddy