Wednesday, May 21, 2025

OIC - Transforming anyType XML to a Namespaced Fragment using XSLT in Integration Flows | Dynamic XML Transformation: Namespace Remapping with xsl:apply-templates in XSLT

Use Case:

In enterprise integrations using Oracle Integration Cloud (OIC) or similar middleware, you may encounter services that accept or return XML fragments typed as xsd:anyType. These fragments can contain any structure, and the lack of a fixed schema or namespace binding makes it difficult to directly map elements in transformations.

For example, a source service might wrap business logic (like GetMeterReadings) inside a generic RequestMessage node with dynamic content. The requirement is to extract the GetMeterReadings fragment and pass it along to the target system with a well-defined target namespace.


Solution:

To handle this dynamic anyType payload, we use XSLT (Extensible Stylesheet Language Transformations) to:

  • Extract the desired fragment (GetMeterReadings) from the dynamic XML.
  • Reconstruct it in a known target namespace (myns1 in this case).
  • Maintain attribute and nested node integrity.

Here’s how it works:

1. Define a generic template to re-map all nodes into a target namespace:

<xsl:template match="*">
    <xsl:element name="myns1:{local-name()}">
        <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
</xsl:template>

2. Apply the template only to the fragment of interest (GetMeterReadings) inside an anyType payload:

<xsl:apply-templates select="//inpl:RequestMessage/inpl:Request/*:GetMeterReadings"/>

3. Declare the required namespaces in the XSLT header:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:inpl="http://example.com/source"
                xmlns:myns1="http://example.com/target"
                exclude-result-prefixes="inpl"
                version="1.0">

Result:

The output of this transformation will be a GetMeterReadings element, moved into the myns1 namespace, ready to be used by the target system.

This approach ensures robust handling of anyType payloads in integrations and allows you to enforce consistent target schemas, even when the source is non-standard.




No comments:

Post a Comment

Featured Post

OIC - OIC Utility to Reprocess Failed Real-Time Integration JSON Payloads

📌 Use Case In real-time OIC integrations, JSON payloads are exchanged with external systems via REST APIs. When such integrations fail (du...