Many times you have a requirement to enrich existing xml objects in a BPEL. I have seen developers using assign activity for that. Assign activity is appropriate if you are adding few mappings. It will be little bit difficult to use assign activity if
- You need to map optional elements. Assign will fail at runtime if the element is not present in the payload. To prevent selection failure you need to add a Switch activity to check for element existence.
- You need to add/append/update a collection of xml elements. It requires a While activity to iterate the collection.
- You need to add mappings for multiple elements.
If you try to do it using Assign your BPEL will be flooded with Switch, Assign and While activities. Your BPEL process become unmanageable its will increase the development time as well. Generally people think the following about XSL transformations:
- XSL transformations are very complex to write.
- They may loose some elements if they use XSL.
So they go with Assign activity and bear all the pains I have mentioned earlier. You can pass multiple source XML objects to an XSL map in SOA 11g. See this post to learn how to pass multiple XML objects to the XSL map. Enriching existing XML using XSL maps is easy in SOA 11g, You just need to follow the steps given below:
1. Add a Transform activity and select the same xml variable as source and target.
2. Add additional variables as source. These variables will be passed as parameters to XSL transformation. See the image given below:
3. Click on Apply and it will open the XSLT map.
4. Map at least one element from each of the additional variables to the target variable. When you add mappings for additional variables, XSL designer defined parameters for additional variables in the XSL. If you want to define parameters manually you can ignore this step.
5. Go to XSL source view and remove the default template and mappings added by the map designer. You can keep XPath expressions in a separate text editor window.
6.Copy the following template in the XSL file:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
This map copies all the elements from source to the target XML. As you are enriching the existing XML, this template will make sure that you don’t loose any xml element.
7. Now it’s the time for customization. You need to add one template per XML element you want to customize. See the following sample template:
<xsl:template match="sample:Line">
<sample:Line xmlns:sample="http://www.oracle.com/Sample">
<xsl:apply-templates select="@* | *"/>
<!-- ADD you custom mappings here. You can also add new elements here-->
</sample:Line>
</xsl:template>
Please note that if you add a template for an XML element it will be applied to that element and its children. You can add new elements, change element values in the XSL templates. Make changes to the above XSL template as per you requirement. Add proper namespace prefixes and declarations.
8. Once done with the XSL, test it in JDeveloper to make sure that it is working fine.
9. Deploy your composite on SOA 11g server and test it.
2 comments:
Yes sir I have the requirement to enrich existing xml objects in a BPEL and I am using assign activity for this thank for exposing different cases and guide to how to deal with this.
Regards,
The Lucidtechsystems providing quality online and Classroom Oracle SOA suite development training and Oracle SOA suite 12c administration training in hyderabad,India.
A Pioneer Institute owned by industry professionals to impart vibrant, innovative and global education in the field of Hospitality to bridge the gap of 40 lakh job vacancies in the Hospitality sector. The Institute is contributing to the creation of knowledge and offer quality program to equip students with skills to face the global market concerted effort by dedicated faculties, providing best learning environment in fulfilling the ambition to become a Leading Institute in India.
cha jaipur
management college in jaipur
management of hospitality administration jaipur
cha management jaipurs
Hotel management in jaipur
Best hotel college in jaipur
Best management college in jaipur
College of Hospitality Administration, Jaipur
Top 10 hotel management in jaipur
Hotel managementin Rajasthan
Post a Comment