Summary: Transforming complex webdynpro tree structure to multiple tabes using XSLT with the perservation of data relationship
Table is the most common data container in SAP world. There may be a situation that you need to convert the data from its original structure to the table structure in order to continue the program logic. One scenario is to convert a tree structure to a table structure or even more than one table. The conversion can be done by using XSLT. It depends on the complexities of the tree and your goals, the corresponding transformation will be different. Consider the following two scenarios:
1. Simple tree structure. This example can be seen in the link http://www.dpawson.co.uk/xsl/sect2/flatten.html
The transformation of this simple structure can easily be achieved by using the <xsl:apply-template/> approach.
2. Complex tree structure.
One example of this type of tree structure is obtained from the webdynpro tree structure. The <item> below the <prod_tree_context> will repeat the same structure as the <item> below the <prod_tree>. This is a type of recursive tree, with "sibling" nodes below the <item>. The goals are to convert the tree to multiple tables and capture the relationship of parent and children as well.
When using the same approach as the first one, this is, using the <xsl:apply-template/>, redundant texts created out of those siblings nodes are appended at the end of each recursive call and leads to an unacceptable result. Therefore, an alternative approach is required.
The following is an XSLT example to achieve transforming this complex tree structure into multiple tables and the parent-children relationship is preserved in the first table.
The result tables of this transformation are the following:
After we obtain the result of transformation, another simple ABAP transformation can convert these data to tables instantly.