XSLT-Making complex XML transformations easy

Data maps are the most common method used for Transformation but they have limited applications when it comes to complex transformations. Data maps are useful where you have one-to-one mapping between source and target XML tags. In case you need to apply certain logic before transformation then you cannot use Data Maps and have to revert to scripting to achieve desired transformation.

It was the solution of a complex problem that made me realize the power and potential of XSLT when it comes to Siebel EAI. Before I jump into the problem and solution let me just give you brief overview of XSLT layman’s term.

XSLT: XSLT stands for EXtensible Stylesheet Language (XSL) Transformations. XSLT uses XPath to actually traverse the XML document and apply transformations based on the user defined rules. You should have knowledge of both XPath and XSLT to use it effectively in Siebel.

Coming back to the problem in Hand. Below is the Source XML that was being generated in Siebel

Source (Obtained from Siebel using EAI Siebel Adapter – Query method)

<?xml version="1.0" encoding="UTF-8"?><
SiebelMessage MessageId="1-18J35" IntObjectName="Test Contact IO" MessageType="Integration Object" IntObjectFormat="Siebel Hierarchical">
<ContactInstance Id="1-1RUYIF" Language="ENU">
<Field Value="Unleashed" Datatype="String" Name="ContactLastName"></Field>
<Field Value="Test Company" Datatype="String" Name="InstallAddress1"></Field>
<Field Value="Test Street 3001" Datatype="String" Name="InstallAddress2"></Field>
<Field Value="TestCity" Datatype="String" Name="InstallCity"></Field>
<Field Value="CL" Datatype="String" Name="InstallState"></Field>
<Field Value="000000" Datatype="String" Name="InstallZipcode"></Field>
<Field Value="Siebel" Datatype="String" Name="ContactFirstName"></Field>
<MVFieldGroup Name="ContactDetails">
<MVField Value="TestValue1" Datatype="String" Name="TestDetail1"></MVField>
<MVField Value="TestValue2" Datatype="String" Name="TestDetail2"></MVField>

I have simplified the source XML to avoid complication the actual XML had complex hierarchical structures going upto 3 levels but the problem statement remained same.

Every Field and MVField Tag should be replaced with value of  “Name” attribute and the value of the Tag should be value of  “Value” attribute. I know it’s confusing. Here is what the Final XML should look like after transformation.

Target Transformation:

<?xml version="1.0" encoding="UTF-8"?>
<SiebelMessage MessageId="1-18J35" IntObjectName="Test Contact IO" MessageType="Integration Object" IntObjectFormat="Siebel Hierarchical">
<ContactInstance Id="1-1RUYIF" Language="ENU">
<InstallAddress1>Test Company</InstallAddress1>
<InstallAddress2>Test Street 3001</InstallAddress2>
<MVFieldGroup Name="ContactDetails">

You would need to write complex scripting solution in order to achieve the same but below is the XSLT that I used to accomplish the same

XSLT Transformation rule:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:apply-templates select="node()|@*"/>
<xsl:template match="Field">
<xsl:element name="{@Name}">
<xsl:value-of select="@Value"/>
<xsl:template match="MVField">
<xsl:element name="{@Name}">
<xsl:value-of select="@Value"/>

The final solution was to :

  • Put the XSLT transformation rule in a file
  • Call EAI Siebel Adapter – Query Method
  • Write the output to a File on the same location as XSLT Transformation rule file
  • Call EAI XSLT ServiceTransform method and provide both file name and locations as input argument
  • Get the Transformed XML as output.

I will write a followup post to explain the XSLT rules used in the example above. You comments and Feedback is welcome as always.

4 Responses to XSLT-Making complex XML transformations easy

  1. Hi,

    I came to know how you have changed the XML to XSLT but but small confusion is that you have give the XSLT rule transformation. If you could explain more about the XSLT rule transformation it would be the grateful and will be appreciated

  2. Hi, 
    nice XSLT example. But can’t the output demostrated here be achieved directly?

    We have Integration Messages in the similar form output directly from the EAISiebelAdapter Query. I believe that it is assured by configuring the INtegration Component Fields … the property XMLStyle= Element. Next property is “XML Tag” where you can defined it to be the same as the BC Field Name



Leave a Reply