Merging XML records into one

Posted by BhanuPratap Tarigopula on Stack Overflow See other posts from Stack Overflow or by BhanuPratap Tarigopula
Published on 2013-10-24T18:48:26Z Indexed on 2013/11/04 9:55 UTC
Read the original article Hit count: 275

Filed under:
|

I am new to XSLT. I have requirement of merging and adding.

XML:

<OrderDetails>
  <OrderDetail action="add">
    <OrderedUnits>18</OrderedUnits>
    <Date>2013-09-30T00:00:00</Date>
    <LocationCode>3202</LocationCode>
    <PONumber>022548295755</PONumber>
  </OrderDetail>
  <OrderDetail action="add">
    <OrderedUnits>12</OrderedUnits>
    <Date>2013-09-30T00:00:00</Date>
    <LocationCode>3202</LocationCode>
    <PONumber>022548295755</PONumber>
  </OrderDetail>
  <IOrderDetail action="add">
    <OrderedUnits>18</OrderedUnits>
    <Date>2013-09-30T00:00:00</Date>
    <LocationCode>3202</LocationCode>
    <PONumber>022548295762</PONumber>
  </OrderDetail>
<OrderDetails> 

If the LocationCode, Date, and PONumber fields match, I need to add the OrderedUnits and make it only one entry.

Expected output XML:

<OrderDetails>
  <OrderDetail action="add">
    <OrderedUnits>30</OrderedUnits>
    <Date>2013-09-30T00:00:00</Date>
    <LocationCode>3202</LocationCode>
    <PONumber>022548295755</PONumber>
  </OrderDetail>
  <IOrderDetail action="add">
    <OrderedUnits>18</OrderedUnits>
    <Date>2013-09-30T00:00:00</Date>
    <LocationCode>3202</LocationCode>
    <PONumber>022548295762</PONumber>
  </OrderDetail>
<OrderDetails>

How can I write this XSLT?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xslt