954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Moving XML Elements with XSLT

Hi peoples,

Suppose I have an XML file

<Application>
  <Segment1>
    <ID>Sam</ID>
    <Fee>2.50</Fee>
    <Fee>1.00</Fee>
  </Segment1>
</Application>


In a nutshell, I want to move the two Elements to another section so it looks like this;

<Application>
  <Segment1>
    <ID>Sam</ID>
  </Segment1>
  <Segment2>
    <Fee>2.50</Fee>
    <Fee>1.00</Fee>
  </Segment2>
</Application>

It would invlove deleting the from the 1st segment and copying it to segment 2.
Any help would be greatly appreciated.

Thanks in advanced

f_atencia
Junior Poster in Training
53 posts since Aug 2009
Reputation Points: 10
Solved Threads: 4
 

By the way, I can only use xml version 1.

f_atencia
Junior Poster in Training
53 posts since Aug 2009
Reputation Points: 10
Solved Threads: 4
 

Check if the works:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"/>

<xsl:template match="Application">
<Application>
	<xsl:apply-templates select="Segment1"/>
	</Application>
</xsl:template>

<xsl:template match="Segment1">
<xsl:copy>
<xsl:copy-of select="ID"/>
</xsl:copy>
<segment2>
<xsl:copy-of select="//Fee"/>
</segment2>
</xsl:template>
mrame
Light Poster
37 posts since Feb 2011
Reputation Points: 10
Solved Threads: 4
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You