Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XSLT for-each for multiple source nodes

JGunJun 14 2017 — edited Jun 20 2017

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.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 18 2017
Added on Jun 14 2017
2 comments
422 views