Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
anirban_pwc
Participant
3,814
Before writing this blog, I thought of coming up with a story line then dropped that plan, because most of the time we google for specific solutions. So, here I'm sharing some of my experiences dealing with different XSLT scenarios.

How to create XSLT Mapping using Altova MapForce:



  1. Get the source and target XML files

  2. In Altova MapForce create a new Mapping: File => New => Mapping

  3. Insert Source & Target XML: Insert => XML Schema/File

    1. This will prompt you to locate corresponding XSD file and if you don’t have that, it’ll create that for you



  4. Now map the nodes from source to target structure




  1. Now go to: Output => XSLT 1.0/2.0, you’ll get the corresponding XSLT mapping:




 

  1. Check the “Output” tab for sample output:




 

 

How to add CDATA tags into output XML using XSLT mapping:


CDATA sections are used to escape blocks of text containing characters which would normally be interpreted as markup. CDATA sections start with "<![CDATA[" and end with the "]]>".

· With Altova MapForce



  1. Right click on the field where you want to add the CDATA and choose “Write Content as CDATA Section”






Select ‘OK’.

 

  1. This with add a “c” on the field denoting CDATA.




3. Corresponding XSLT will look like:



  1. And output will be as following:



· Without Altova MapForce


We need to know how to achieve CDATA mapping without the help of AMF because in some cases AMF doesn’t support CDATA mapping.

For example, CDATA is not support in any node other than a leaf one.



In this case add the following piece of code where you want to add the CDATA.



 

The Output will add CDATA before the <gridfield> tag.



 

 

How to add extra tags which are not there in the Input but required in the Output:


You need to simply mention the extra tag in the XSLT mapping.

In our previous example, we didn’t have the tag <gridfield> in the incoming XML but we needed that in the output XML, hence just added that corresponding opening & closing tags in the right places.

 

How to add additional identifiers in the Output XML tag:


Tags with special characters are not supported in the SAP PI Message Mapping. In those cases, we can use XSLT mapping to add additional identifies to an existing XML tag.

Let’s consider previous XML structures for example. In that we didn’t have any prefix in any of the output XML tags.

Now, if the requirement is to add “urn:” in every <name> and <value> tags in the output XML then you need to declare that in the beginning.

 

Example:

Input XML –



 

Corresponding XSLT Mapping:



Output XML:



If you don’t declare the prefix namespace in the beginning, then you’ll receive following error:



 

Hope this be useful for you. Happy learning and sharing 🙂
Labels in this area