XSLT (Extensible Stylesheet Language Transformation) is used to transform XML documents from one format to other format. While developing processes in TIBCO during application’s integration, XML transformations are often required.
In this tutorial, you will learn step by step how to transform XML from one format to another format in TIBCO using XSLT.
Step 1: Create Source XML File and XSD Schema
In order to go forward with TIBCO XSLT tutorial, first thing that we need to do is source XML file creation. In this tutorial example, we are going to use following source XML which will be transformed to another format using XSLT transformation:
Source XML File:
We need to create XSD Schema in our TIBCO BW project for this source XML File. By dropping XSD schema in your designer panel, create Schema as shown below:
Step 2: Create target Schema
In this tutorial, we want to take above XML as input and want to convert it into a new format based on the below target schema:
Step 3: Create XSLT for XML Transformation in TIBCO
Now that we are clear about our source XML schema and target XML Schema, we need to write XSLT code which will be used for XML transformation.
We will take Age from the source XML and give a value “Eligible” to the Status field in the target XML if age is greater than 20 years. Otherwise, our target XML will have Status as “Not Eligible“.
To achieve this XML Transformation, our XSLT will be as shown below:
<xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” version=”1.0″>
<xsl:for-each select=”EmployeeList/Employee” >
<xsl:value-of select=”Name” />
Step 4: Create TIBCO BW Process for XSLT Based XML Transformation
Now we need to create a process where we will be performing source XML parsing, rendering, transformation and then target XML Parsing. To keep the scenario simple, I haven’t added any exception handling in the process for now.
I have used a Read File activity to read the source XML from local file system. In the Input tab of Read File activity, file to be read is specified as shown below:
After reading source XML File, we need to use Parse XML activity to parse the file contents based on our source XML XSD schema that we created in Step 2.
Parse XML Input tab will be as shown below:
In the output editor of Parse XML activity, we choose XSD file for the source XML File as you can see in below screenshot:
Just to make you more clear and well aware about XML Parsing and XML Rendering, I have used Render XML activity which will be used to create XML string which will be later provided as Input to Transform XML activity.
Configuration tab of Render XML activity is shown below:
In the Input Editor tab of Render XML activity, we specify the XSD schema to be used for rendering XML file. This is shown in below screenshot:
And then, in the Input tab of Render XML activity, we map Parse XML output by choosing Copy-of option as shown in the below screenshot:
Now that we are done with Parsing and Rendering of our source XML File, we move towards Transform XML activity which will be used to create our target XML based on the XSLT file that we created earlier.
In the configuration tab of Transform XML activity, we have chosen XSLT file to be used, Input and Output Style and XSLT engine. Complete configuration of XML Transform activity is shown below:
In the Input tab of Transform XML activity, we map the source XML from Render XML output as you can see in the screenshot below:
After transformation of XML file from one format to another using XSLT, our next step will be to parse the new XML file for which we use Parse XML activity to which we give transformed XML as input as shown below:
In the output editor tab of this Parse XML activity, we choose our target XSD schema which was created in step 2.
Output editor tab of this activity is shown in below screenshot:
That’s it for process development. We are done with the configuration of all the activities in our process. Validate the project and after successful validation, move to the next step where we will test our XSLT based transformation process.
Step 5: Test XSLT Transformation Process in TIBCO
Load the process in designer tester. As you can see in below screenshot, our process has run successfully. Everything seems fine:
Now let’s go to different activities in tester mode and verify that everything has worked the way we wanted.
Go to the output tab of Parse Source XML activity to see if XML File read by Read File activity has been parsed correctly. As shown in the below screenshot, this parsing has gone correctly:
Now go to the Output tab of Render XML activity to see if it has resulted in rendering of XML correctly as a string. Yes, below screenshot shows that Render XML activity has given the XML string rightly:
Now we need to check and verify that Transform XML activity has created output properly based on our XSLT File. Go to the output tab of Transform XML activity. As you can see below, this activity has created output XML correctly based on the XSLT file that we had specified:
And the last thing to test is the Parse XML activity to verify that our target XML file created by XSLT transform activity has been parsed correctly based on our target XML schema.
As shown below, parsing of target XML is successful: