Note: This example illustrates the transformation process used in general XML to XML transformation (transformation is not limited to StoryTeller).In this example the data source is the same as in Data driven example. The difference in this example is that you not only want to preserve the order but also the exact structure of elements, and not add any extra event element. In a situation like this you can use the special form union.
<data>
<message>
<header owner="John Smelter" number="+4202468999"/>
<call number="+4207654321" cost="3.23" duration="125"/>
<sms number="+4201234567" cost="0.15" text="Hello!"/>
<sms number="+4207654321" cost="0.12" text="Hi!"/>
<mms number="+4207654321" cost="0.45" bytes="12432"/>
<mms number="+4201234567" cost="0.75" bytes="32457"/>
<sms number="+4201234567" cost="0.15" text="Cheers!"/>
<call number="+4207654321" cost="1.67" duration="67"/>
<sms number="+4201234567" cost="0.15" text="Good bye!"/>
<mms number="+4207654321" cost="0.45" bytes="12345"/>
</message>
</data>This is the data source to process. The call, sms and mms elements come in an arbitrary order, and you want to preserve the order AND structure for presentation.
<data>
<message>
<header owner="John Smelter" number="+4202468999"/>
<call number="+4207654321" cost="3.23" duration="125"/>
<sms number="+4201234567" cost="0.15" text="Hello!"/>
<sms number="+4207654321" cost="0.12" text="Hi!"/>
<mms number="+4207654321" cost="0.45" bytes="12432"/>
<mms number="+4201234567" cost="0.75" bytes="32457"/>
<sms number="+4201234567" cost="0.15" text="Cheers!"/>
<call number="+4207654321" cost="1.67" duration="67"/>
<sms number="+4201234567" cost="0.15" text="Good bye!"/>
<mms number="+4207654321" cost="0.45" bytes="12345"/>
<footer events="9" total="7.120000000000001"/>
</message>
</data>
<data>
<message>
<header owner="?" number="?"/>
<call number="?" cost="?" duration="?"/>
<sms number="?" cost="?" text="?"/>
<mms number="?" cost="?" bytes="?"/>
<footer events="?" total="?"/>
</message>
</data>The data template is created as an ordinary data template, as if you know the order (header first, then call, sms and mms). A new footer element is also added. This element contains summary data: number of events (@events) and sum of all costs (@total).The important part is that all data ordered elements must be defined together. The order of the grouped elements (call, sms and mms) is arbitrary, while the order of the group itself in respect to other elements (header, footer) is important.
<tdt:transformation>
<tdt:rule path="/data/message">
<tdt:value key=".">/data/message</tdt:value>
<tdt:value key="$events">*[self::call|self::sms|self::mms]</tdt:value>
</tdt:rule>
<tdt:rule path="/data/message/header">
<tdt:value key=".">header</tdt:value>
<tdt:value key="recurse">.</tdt:value>
</tdt:rule>
<tdt:rule path="/data/message/call">
<tdt:value key="union">$events</tdt:value>
<tdt:value key=".">self::call</tdt:value>
<tdt:value key="recurse">.</tdt:value>
</tdt:rule>
<tdt:rule path="/data/message/sms">
<tdt:value key="union">$events</tdt:value>
<tdt:value key=".">self::sms</tdt:value>
<tdt:value key="recurse">.</tdt:value>
</tdt:rule>
<tdt:rule path="/data/message/mms">
<tdt:value key="union">$events</tdt:value>
<tdt:value key=".">self::mms</tdt:value>
<tdt:value key="recurse">.</tdt:value>
</tdt:rule>
<tdt:rule path="/data/message/footer">
<tdt:value key="@total">sum($events/@cost)</tdt:value>
<tdt:value key="@events">count($events)</tdt:value>
</tdt:rule>
</tdt:transformation>In order to switch locally from design driven to data driven mode the special form union is used. The data transformation should do as follows:
1
2 Evaluate <header> (design driven mode).
3 Evaluate the union (data driven mode). The call, sms and mms all share the same union value and form a single group.
4 Evaluate <footer> (design driven mode).
| OpenText StreamServe 5.6.2 | Updated: 2018-01-26 |