Enhancing Data Transformations in OIC with Custom XSLT Functions

Oracle Integration Cloud (OIC) is a robust platform designed to simplify and accelerate the integration of cloud. One of its most powerful features is the XSLT Mapper, which enables developers to define and manage data transformations visually. While OIC’s built-in XSLT 1.0 functions cover a wide range of scenarios, there are times when these standard functions fall short—especially in more complex or business-specific transformations.
This is where custom functions become a game changer.
Why Use Custom Functions in OIC?
Custom functions allow developers to go beyond the limitations of built-in capabilities by embedding custom logic directly into the XSLT Mapper. These functions can be defined using XPath expressions . This added flexibility is crucial for handling complex transformations, validations, or string manipulations that are otherwise not feasible using standard tools.
What You’ll Learn in This Blog
In this blog, we will walk through:
The benefits of using custom functions in OIC.
A real-world example showcasing the creation and use of a custom function to meet a specific transformation requirement.
Real-World Scenario: Padding a Numeric Value to Fixed Length
Step 1: Define the Use Case
Imagine a business scenario where you receive a fixed-length file from a source system. The target system requires that the final line of the file includes a record count, formatted as a 7-digit number with leading zeroes. The source data structure looks like this:
<RecordSet xmlns="http://TargetNamespace.com/fileReference/ReadFileInStage">
<Record><C1>C1179703</C1></Record>
<Record><C1>C1179704</C1></Record>
<Record><C1>C11797013</C1></Record>
<Record><C1>C11797014</C1></Record>
</RecordSet>
The required output should look like this:
<ns41:Recordset>
<ns41:Record><ns41:C1>C1179703</ns41:C1></ns41:Record>
<ns41:Record><ns41:C1>C1179704</ns41:C1></ns41:Record>
<ns41:Record><ns41:C1>C11797013</ns41:C1></ns41:Record>
<ns41:Record><ns41:C1>9000004</ns41:C1></ns41:Record>
</ns41:Recordset>
Step 2: Define a Custom Namespace as myfunc
xmlns:nsmpr11="http://xmlns.oracle.com/cloud/adapter/stagefile/WriteCurrentFileInstage_REQUEST/types" xmlns:func="myfunc"
xmlns:nsmpr12="http://xmlns.oracle.com/cloud/adapter/atpdatabase/GETBUID_REQUEST/types" version="2.0" xml:id="id_1" exclude-result-prefixes=" ora oracle-xsl-mapper dvm oraext xsi xsd fn xp20 xsl nssrcmpr ignore01 nsmpr0 nsmpr1 nsmpr2 nsmpr3 nsmpr4 nsmpr5 nsmpr6 nsmpr7 nsmpr8 nsmpr8 nsmpr5 ns37 nsmpr8 nsmpr5 ns37 fn fn nsmpr5 ns37 fn fn nsmpr5 ns37 nsmpr9 nsmpr10 myfunc nsmpr11 nsmpr12" ignore01:ignorexmlids="true">
Step 3: Define a Custom Function
<xsl:function name="func:padStr">
<xsl:param name="str"/>
<xsl:param name="chr"/>
<xsl:param name="len"/>
<xsl:variable name="pad">
<xsl:for-each select="1 to $len">
<xsl:value-of select="$chr"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="concat($pad,$str)"/>
</xsl:function>
How It Works:
str
: Input string.len
: Calculates how many characters are needed to reach the total length.The loop (
1 to $len
) creates only as many characters as necessary and stores in$chr
.Final result of
$chr
is stored in$pad
.Finally,
concat($pad, $str)
builds the padded result.
Step 4: Use the Function in the Template
<ns41:C1>
<xsl:value-of select="concat('9', func:padStr(count($ReadFileInStage/nsmpr5:ReadResponse/ns37:RecordSet/ns37:Record), 0, 6 - string-length(string(count($ReadFileInStage/nsmpr5:ReadResponse/ns37:RecordSet/ns37:Record)))))"/>
</ns41:C1>
Step 5: Map the Output
Assign the result of the function directly to the target field. This encapsulates your logic cleanly and promotes reusability across integrations.
Step 6: Test and Validate
Always test your transformation using the built-in OIC Mapper test framework. Input sample payloads and preview the output to ensure it meets the business requirement.
Conclusion
Custom functions in OIC’s XSLT Mapper are invaluable for delivering sophisticated and scalable integration solutions. They provide a clean way to extend transformation capabilities, encapsulate business logic, and promote reusability across projects.
By following best practices—such as modular function design, meaningful naming conventions, and thorough testing—you ensure your integrations are not only functional but also maintainable in the long run.
Incorporating custom functions into your OIC toolbox elevates your ability to build high-performance, enterprise-grade integrations that meet the ever-evolving demands of modern businesses.
Subscribe to my newsletter
Read articles from Saptarshi Ray directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
