All posts

XSLT or Message Mapping in CPI: When to Use Which?

SAP Cloud Integration offers several ways to transform messages. Message Mapping and XSLT are the two most common tools for structural transformations. Both have their place. This post shows when each is the better choice.

Mapping options in CPI at a glance

Before diving into the comparison, a quick overview of all options:

  • Message Mapping: Graphical tool; fields are connected by drag-and-drop, functions configured by click.
  • XSLT Mapping: Transformation via an external XSLT file; full programmatic control over the output.
  • Operation Mapping: Import from the SAP Enterprise Services Repository (ESR); relevant in PI/PO migration scenarios.
  • Groovy or JavaScript Script: Not a dedicated mapping type, but usable as a script step in the integration flow when other tools fall short.

In everyday project work, Message Mapping and XSLT are the main candidates. The choice between the two often determines how maintainable an integration flow remains long-term.

Message Mapping: strengths and limits

Message Mapping is what most beginners encounter first. It looks intuitive: source structure on the left, target structure on the right, draw lines, done.

SAP CPI Message Mapping Editor with graphical field assignments
The Message Mapping Editor in SAP Cloud Integration: fields are connected graphically, functions configured by click.

Strengths:

  • No code required: people without development experience can create and maintain simple mappings themselves.
  • Built-in test function: a mapping can be tested with sample data directly in the editor.
  • MIG and MAG integration: via SAP Integration Advisor, Message Implementation Guides and Mapping Guidelines can be imported and used as a basis, especially helpful for standard formats like EDIFACT or IDoc.
  • Fast start: for simple, flat 1:1 mappings you are done in minutes.

Limits:

  • Click-heavy: every function, every condition, every loop is configured graphically. As complexity grows, this becomes time-consuming and hard to read.
  • Poor versioning: the mapping is stored internally as XML. A git diff on that file is barely readable because small content changes produce large structural diffs.
  • Test function breaks under complexity: dynamic mappings, context-dependent functions or large payloads often cause the built-in test to fail or simply return nothing, with no clear error message.
  • Hard to analyse with LLMs: the graphical state of a mapping cannot easily be passed to a language model. An XSLT file, by contrast, is plain text.

XSLT Mapping: strengths and limits

XSLT is a declarative, XML-based language designed specifically for transforming XML documents. In CPI, an external XSLT file is loaded into the integration package and referenced in the XSLT Mapping step.

Strengths:

  • Full control: everything the mapping does is in the code. No hidden state, no click puzzle.
  • Overview at a glance: even complex transformations with loops, conditions and multiple templates are readable in a single file.
  • Clean versioning: a git diff on an XSLT file shows exactly what changed. Code reviews are possible.
  • LLM-friendly: an XSLT file can be pasted directly into a chat with Claude or ChatGPT. The model can explain, refactor, find bugs and suggest improvements without losing context.
  • Reusable templates: XSLT supports named templates and import mechanisms for extracting shared logic.
  • External testability: XSLT can be tested locally with sample XML, independent of the CPI runtime.

Limits:

  • Learning curve: anyone unfamiliar with XML and functional programming logic needs time to get comfortable with XSLT.
  • No native tooling in CPI: there is neither syntax highlighting nor a live test directly in the integration package editor. Development happens locally; the file is uploaded.
  • External tooling required: for comfortable development, syntax checking and formatting you need an external tool like VS Code with an XML/XSLT extension. That means an extra step in the workflow: write locally, upload to the CPI package, test.
  • No MIG/MAG integration: SAP Integration Advisor cannot generate XSLT files directly. Anyone who relies on that workflow stays with Message Mapping.

Code example: an XSLT mapping in practice

The following example shows a typical transformation: a source XML is restructured, fields are renamed and a conditional element is added.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" indent="yes" encoding="UTF-8"/>

  <xsl:template match="/">
    <Order>
      <xsl:apply-templates select="PurchaseOrder"/>
    </Order>
  </xsl:template>

  <xsl:template match="PurchaseOrder">
    <!-- Rename fields -->
    <OrderId><xsl:value-of select="PONumber"/></OrderId>
    <Supplier><xsl:value-of select="Vendor/Name"/></Supplier>

    <!-- Conditional output -->
    <xsl:if test="Priority = 'HIGH'">
      <Urgent>true</Urgent>
    </xsl:if>

    <!-- Loop over line items -->
    <Items>
      <xsl:for-each select="LineItems/Item">
        <Item>
          <MaterialNumber><xsl:value-of select="@id"/></MaterialNumber>
          <Quantity><xsl:value-of select="Qty"/></Quantity>
        </Item>
      </xsl:for-each>
    </Items>
  </xsl:template>

</xsl:stylesheet>

You can paste this code directly into a chat with an LLM and ask: "Why does this mapping return no output?" or "Add a condition that skips empty fields." That works reliably because XSLT is plain text.

When to prefer XSLT

  • The mapping has more than a handful of fields or requires loops and conditions.
  • The source data has nested or repeating structures that are hard to represent graphically.
  • Multiple people work on the same integration flow and code reviews should be possible.
  • The mapping needs to be created, debugged or optimised with the help of an LLM.
  • There are many similar mappings, for example in a migration project, that can be shared via common templates.
  • The integration flow will be maintained long-term and the logic must still be understandable a year from now.
  • Large payloads or dynamic inputs make the built-in test mechanism of Message Mapping unreliable.

When to prefer Message Mapping

  • It is a simple, flat 1:1 mapping with no complex logic.
  • The business department or a junior without a development background should be able to maintain the mapping themselves.
  • The scenario is based on SAP Integration Advisor with MIGs and MAGs, for example in EDIFACT or IDoc scenarios.
  • A quick prototype is needed and longevity is not a concern.
  • The team has no capacity for local XSLT tooling and wants to do everything directly in CPI.

Conclusion

Both tools have their place. Message Mapping lowers the entry barrier and is the right choice for simple scenarios and MIG/MAG-based integrations. XSLT scales better with growing complexity, versions cleanly and works well in combination with LLMs.

A good rule of thumb: as soon as a mapping becomes hard to read in the graphical editor or the test mechanism stops working, switching to XSLT is usually the smarter investment. The extra effort from external tooling pays off quickly once the mapping grows or needs frequent changes.