Copy existing XML, duplicate element and modify

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-06-15T12:19:41Z Indexed on 2010/06/15 12:22 UTC
Read the original article Hit count: 162

Filed under:
|

Hi,

I have a tricky XSL problem at the moment. I need to copy the existing XML, copy a certain element (plus its child elements) and modify the value of two child-elements. The modifications are: divide value of the 'value' element by 110 and edit the value of the 'type' element from 'normal' to 'discount'.

This is currently what I have:

Current XML:

<dataset>
  <data>
   <prices>
    <price>
      <value>50.00</value>
      <type>normal</type>
    </price>
  </prices>
 </data>
</dataset>

Expected result

<dataset>
  <data>
   <prices>
    <price>
      <value>50.00</value>
      <type>normal</type>
    </price>
    <price>
      <value>45.00</value>
      <type>discount</type>
    </price>
  </prices>
 </data>
</dataset>

Any takers? I've gotten as far as copying the desired 'price' element using copy-of, but I'm stuck as to how to modify it next.

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xslt