In this post I will explain how to add a variable into a XSL code. I will also explain why do we need it at all.
(This option exists on both Oracle SOA Suite 10g and 11g versions. Some of the screens might be a little bit different. Below I’ve attached print screens from 11g)
If you are using a transformation activity in your process, you probably need to do some mapping for multiple records data.
Like in other developing languages, there are cases where you want to declare a variable once, assign to it a value, and use it later on in your code.
When using xsl for mapping source to target, it is the same behavior.
Let’s take 2 scenarios:
Scenario 1:
You are running an interface that reads 10,000 records from a tables in a DB, and assign it to a file. For this assignment task, you are using a transform activity.
Now, one of the file columns needs to hold the interface date on a millisecond level. If you will calculate the date, for each record, you might get a different outcome for each few records.
Scenario 2:
You are running an interface that reads 10,000 records from one file, and assign it to another file. For this assignment task, you are also using a transform activity. In this scenario, you have to query a DB to get a sequence for the interface, and assign it to one of the file columns.
On both scenarios, you can declare a variable, and assign it for each one of the records.
The advantage of using a variable:
- Reduce the execution time
- Ensure accuracy of information (like in scenario 1)
- Reduce performance issues (like in scenario 2 – instead of 10,000 DB transaction you will use 1)
So how to do it:
Open the transform activity and edit the xsl file (Here I’m using the design view).
Right click on the root element and press “Add Variable..” in the menu:
Enter the variable name and press ok. On both 10g and 11g versions you can set from this screen the variable type and a default value.
Now you can just assign for it the required data. In my example I’ve assigned to it a DateTime function:
From the component palate go to advanced function and drag the “xpath-expression” activity. Enter the variable name you’ve created prefixed by $
Assign the “xpath-expression” activity to your target element and that’s it.
The source code it should look like that:
Good Luck
Leave a Reply