Friday, September 26, 2025

OIC - How to Use XSLT to Generate Namespaced Target Payload Blocks in OIC

Use Case

When working with Oracle Integration Cloud (OIC) SOAP-based integrations, we often need to map fault objects (like error details or reasons) into a target response payload that follows a specific namespace and schema.

In this example, the target system expects a payload with the following structure:

<ns2:AddMeterToInventoryResponse xmlns:ns2="turtletech.com/TS2/">
   <ns2:AddMeterToInventoryResult>
      <ns2:ErrorObj>
         <ns2:errorString>Meter Not Added</ns2:errorString>
      </ns2:ErrorObj>
   </ns2:AddMeterToInventoryResult>
</ns2:AddMeterToInventoryResponse>

The challenge is to generate this block dynamically from fault objects (like $GlobalFaultObject/nspr1:fault) while preserving the correct namespace (ns2) and nested structure.


Solution with XSLT Mapper

To achieve this in OIC mapper, we can leverage <xsl:apply-templates> and define templates that build the required XML block.


1. Declare the Namespace

In your stylesheet, ensure that the target namespace (ns2) is declared:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ns2="turtletech.com/TS2/"
                xmlns:nspr1="http://schemas.oracle.com/faults"
                exclude-result-prefixes="nspr1"
                version="1.0">

2. Entry Template

Start with a root template that applies templates for faults:

<xsl:template match="/">
   <nstrgmpr:InboundSOAPResponseDocument>
      <nstrgmpr:Body>
         <xsl:apply-templates select="$GlobalFaultObject/nspr1:fault"/>
      </nstrgmpr:Body>
   </nstrgmpr:InboundSOAPResponseDocument>
</xsl:template>

3. Fault Handling Template

Define how the fault is transformed into the required target structure:

<xsl:template match="nspr1:fault">
   <ns2:AddMeterToInventoryResponse>
      <ns2:AddMeterToInventoryResult>
         <xsl:choose>
            <xsl:when test="$GlobalFaultObject/nspr1:fault/nspr1:details = ''">
               <ns2:ErrorObj>
                  <ns2:errorString>
                     <xsl:value-of select="$GlobalFaultObject/nspr1:fault/nspr1:reason"/>
                  </ns2:errorString>
               </ns2:ErrorObj>
            </xsl:when>
            <xsl:otherwise>
               <ns2:ErrorObj>
                  <ns2:errorString>
                     <xsl:value-of select="$GlobalFaultObject/nspr1:fault/nspr1:details"/>
                  </ns2:errorString>
               </ns2:ErrorObj>
            </xsl:otherwise>
         </xsl:choose>
      </ns2:AddMeterToInventoryResult>
   </ns2:AddMeterToInventoryResponse>
</xsl:template>


4. Execution

With this template setup:

  • OIC picks up the fault object.
  • The <xsl:apply-templates> dispatches it to the fault template.
  • The correct namespace-prefixed block (ns2) is generated.

This ensures your output matches the required schema exactly and avoids namespace mismatches.


Key Takeaways

  • Always declare the target namespace (ns2) in the XSLT stylesheet.
  • Use <xsl:apply-templates> and <xsl:template match> to modularize transformation logic.
  • Use <xsl:choose> to conditionally pick reason or details from fault objects.
  • This approach guarantees a reusable and scalable mapping for multiple fault scenarios.

👉 This method is highly reusable for any SOAP service response transformation in OIC where a specific namespace-aligned block must be built dynamically.



No comments:

Post a Comment

Featured Post

OIC - How to Encrypt and Decrypt Using AES Key and OCI Function in Oracle Integration Cloud (OIC)

 Working... 📌 Use Case In real-world Oracle Integration Cloud (OIC) projects, sensitive data like passwords, API keys, or personal informat...