0
votes

I need to rip some xml nodes from a xml document. The source is

<root>
    <customElement>
        <child1></child1>
        <child2></child2>
    </customElement>
    <child3></child3>
    <child4></child4>
</root>

the result should be

<root>
    <child1></child1>
    <child2></child2>
    <child3></child3>
    <child4></child4>
</root>

As you can see only the 'customElement' element is removed, but the child elements are still part of the result document. How can I do this using xslt transformation.

1
can you show us your attempt? - Mitch Wheat
The same question has been asked before: stackoverflow.com/questions/1524786/… - Jukka Matilainen

1 Answers

2
votes

Here's a simple solution:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>

<!-- identity template -->
<xsl:template match="@*|node()">
    <xsl:copy>
       <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<!-- here we specify behavior for the node to be removed -->
<xsl:template match="customElement">
   <xsl:apply-templates select="@*|node()"/>
</xsl:template>

</xsl:stylesheet>