Service Bus 12c – Using XSL map

In this post, you will learn to create and use XSL maps in message flow using the same Service Bus project used in previous posts.

clip_image002[4]_thumb[2]

And here we are creating XSLT map for Customer transformation. The Source WSDL CustomerPS.wsdl and Target WSDL CustomerService.wsdl  are available here and here respectively. Make sure that you have these WSDLs copied in your project before proceeding with XSL map creation.

Creating XSL map:

Right click XSLTs folder in XYZCustomer project and select New -> XSL Map and give File Name as CustomerPSToUpdateCustomer.

clip_image001

Click Browse for Primary Source to bring up Select Schema screen.

clip_image003

Retain default selection and click Browse to select the source element.

clip_image004

Click OK twice to go back to Create XSL Map screen. Now click Browse for Target to bring up Select Schema screen again. And click Browse for Select Schema and select the target element as shown below.

clip_image006

Click OK twice and observe Source and Target elements.

clip_image008

Click OK to finish that brings up XSLT Transformation editor as shown below.

clip_image010

Here we are planning to do update of Customer Information, so you should not send null values in payload to business service; hence Target elements should be mapped only when corresponding Source element is available.

You can achieve this behavior automatically in XSL Map editor by setting a preference. Go to Tools -> Preferences and set property as shown below.

clip_image012

Now go back to XSL Map editor and do the initial mapping as shown below by connecting respective Source and Target elements. Observe that xsl:if condition gets added automatically when source element is defined as optional in schema.

clip_image014

Drag concat function into middle swim lane from Components-> General XPath -> String Functions to concatenate FirstName, Lastame and map to full_name. Also concatenate State, Country and ZipCode and map to addr_line4 as shown below.

clip_image016

Click concat functions and modify them to add  ‘,’ between elements as shown below.

clip_image018

clip_image020

Now go to Source and modify full_name and addr_line4 elements mapping to include xsl:if conditions so that Target will be mapped only when all of the  corresponding Source elements are present.

clip_image022

clip_image024

Testing XSL map:

It’s always advisable to test your XSL map to see whether mapping is working as expected. Click Test XSL Map icon in editor to bring up the following screen.

clip_image026

Click OK and observe that mapping is working as expected as shown below. You can also verify that both Source and Target xml files are generated. You can modify source xml and retest your XSL map again.

clip_image028

Using XSL map in Message Flow:

Drag Replace activity from Message Processing into message flow at place wherever you require transformation. In Properties tab, bring up expression editor for Value property and choose XSL map as shown below.

clip_image030

clip_image032

Click OK and give Input Document Expression as $body/*.

clip_image034

Set other properties as shown below. This action will replace the contents of $body context variable with transformed payload.

clip_image036

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.




Pages

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 379 other subscribers

Enter your email address to follow this blog and receive notifications of new posts by email.


%d bloggers like this: