XSLT Mapping or Scripts in SAP CPI

This blog will provide points to consider while choosing XSLT mapping or Scripts in SAP CPI. As such there are no straight guidelines on using one over the other – it depends on the use case.

The integration platform is used to translate between different message formats. These transformations are known as mappings and SAP CPI offers its own set of tools for building them, namely.

  • Message mapping
  • XSLT
  • JavaScript and Groovy scripting

Sometimes it becomes difficult to make the choice between the mappings, In this article, I have come up with some points which can help to choose between XSLT or Scripts in SAP CPI.

Here are some points which can help in making a decision:

  1. Datatype changes can prove to be very expensive and may bring down the performance. Try to keep the conversions to the minimum – e.g. if the message is the output of an XSLT as a DOM Document, converting it to InputStream and then parsing it into DOM will cause quite some overhead
  2. If you need to change the XML structure, like cloning a node or deleting a node, etc., it is easy and quick to develop it using XSLT.
  3. Do not convert an XML to string and perform string operations to manipulate the XML. Make use of parsers within the script.
  4. If you need to perform some calculations based on the XML data and set some variables, an optimal instrument would be a script.
  5. XML parsing within a script is susceptible to XXE attacks (XML External Entity attacks) – instead request a specific payload type as this will trigger type conversion implicitly. This will not be prone to any attacks as the parser that is running during that conversion is secure. For example, instead of requesting the message body as an InputStream and then parsing it into a Document, you can request the message body as a Document.
  6. XSLT makes use of the Saxon parser, so whatever holds good for Saxon over SAX, STAX, or DOM parsers also apply here.
  7. Consider the parser capabilities and footprint before choosing a DOM parser over SAX/STAX-Although it may be easy DOM parsing the XML in the script, it is important to note that DOM parsers are memory intensive as they load the entire XML in memory and create the XML tree from it. This is an important consideration, especially when working with big datasets as they can cause an out-of-memory situation. However, if the dataset is not huge, DOM parsing can prove to be more performant. DOM parsing can also be a better choice when you need to parse the XML back and forth.SAX/STAX is very helpful when working with huge datasets as they stream the XML and do not load the entire XML in memory. Moving the XML back and forth may be expensive with these parsers.

 

Refer https://blogs.sap.com/2017/06/20/stream-the-xmlslurper-input-in-groovy-scripts/.

More SAP CPI Blogs

ODATA Adapter in SAP CPI

How to Test Iflow in SAP CPI

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.