I'm trying to convert below Source XML to Target XML using xslt.
In Source xml I have multiple action
tags. For every action/action_kind/code='pickup'
there will be another action/action_kind/code='deliver'
In both action
tags orderId
is same.
I need to pick the from
and to
tags based on this and I need to populate the Target XMLas shown below
I'm looking for a xslt solution which will convert the Source XML to Target XML
Source XML
<section>
<action>
<action_kind>
<code>pickup</code>
</action_kind>
<pickup>
<orderId>11</orderId>
</pickup>
<name>NameOne</name>
<address>AddressOne</address>
</action>
<action>
<action_kind>
<code>pickup</code>
</action_kind>
<pickup>
<orderId>22</orderId>
</pickup>
<name>NameTwo</name>
<address>AddressTwo</address>
</action>
<action>
<action_kind>
<code>deliver</code>
</action_kind>
<expected>
<from>FirstOrderFro</from>
<to>FirstOrderTo</to>
</expected>
<delivery>
<orderId>11</orderId>
</delivery>
</action>
<action>
<action_kind>
<code>deliver</code>
</action_kind>
<expected>
<from>ScondOrderFro</from>
<to>SecondOrderTo</to>
</expected>
<delivery>
<orderId>22</orderId>
</delivery>
</action>
</section>
Target XML
<Orders>
<Order>
<OrderId>11</OrderId>
<Name>NameOne</Name>
<Address>AddressOne</Address>
<From>FirstOrderFro</From>
<To>FirstOrderTo</To>
</Order>
<Order>
<OrderId>22</OrderId>
<Name>NameTwo</Name>
<Address>AddressTwo</Address>
<From>SecondOrderFro</From>
<To>SecondOrderTo</To>
</Order>
</Orders>
The question is when I use for-each on action tag I am getting 4 Order tags in Target XML. I want only 2 Order tags which will club 2 action tags based on orderId.