Dear Friends good afternoon. My problem may be this is very basic one i.e. how can we remove root element from a xml file using xslt. Xml file example given below.
<Result>
<Jobs id="1">
<Job ID="000000" PositionID="0000">
<Title>Development Manager - Investment Banking - Equities Business</Title>
<Summary><![CDATA[An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.   My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t]]></Summary>
<DateActive Date="2009-10-06T19:36:43-05:00">10/6/2009</DateActive>
<DateExpires Date="2009-11-05T20:11:34-05:00">11/5/2009</DateExpires>
<DateUpdated Date="2009-10-06 20:12:00">10/6/2009</DateUpdated>
<CompanyName>ABC Technology</CompanyName>
</Job>
</Jobs>
</Result>
So, I want the output as below
<Jobs>
<Job ID="000000" PositionID="0000">
<Title>Development Manager - Investment Banking - Equities Business</Title>
<Summary><![CDATA[An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.   My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t]]></Summary>
<DateActive Date="2009-10-06T19:36:43-05:00">10/6/2009</DateActive>
<DateExpires Date="2009-11-05T20:11:34-05:00">11/5/2009</DateExpires>
<DateUpdated Date="2009-10-06 20:12:00">10/6/2009</DateUpdated>
<CompanyName>ABC Technology</CompanyName>
</Job>
</Jobs>
So, No more
<Result></Result>
tags in the xml file. Pls. help. Thanks in advance.
The removeChild() method removes a specified node. The removeAttribute() method removes a specified attribute.
The XML root element represents the XML document that is being mapped. The XML root element is a looping structure that contains elements and content particles that repeat in sequence until either the group data ends or the maximum number of times that the loop is permitted to repeat is exhausted.
Each XML document has exactly one single root element. It encloses all the other elements and is, therefore, the sole parent element to all the other elements.
Every XML document must have a root tag which enclose the XML document.
<!-- identity template -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<!-- template for the document element -->
<xsl:template match="/*">
<xsl:apply-templates select="node()" />
</xsl:template>
The identity template copies everything as it is, while the template for the document element only takes care of the child nodes (handing them over to the identity template) while not copying the root node itself.
If you want to keep your <summary>
as CDATA for some reason, you will need
<xsl:output cdata-section-elements="summary" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With