Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Best Way To Strip XML Document of Unwanted Nodes >Thread Next - Re: Best Way To Strip XML Document of Unwanted Nodes Re: Best Way To Strip XML Document of Unwanted NodesTo: NULL Date: 10/5/2005 4:35:00 PM "Eddy C" <eddy73@g...> wrote in message news:1128466924.702660.210370@g...... > I'm trying to strip an XML document of unwanted nodes such that in the > example below I would keep all the parent nodes of a child node I > wanted and for other parents which do not have the child requested they > would be stripped. > > I understand I could use XSLT but I'm doing this in java and was > wondering if there was a preferred approach out there. > > > Before > <a> > <b> > <c>fdfdsf</c> > </b> > <b> > <x>dffsd</x> > </b> > <b> > <x>dffsd</x> > <c>fdfdsf</c> > </b> > </a> > > After requesting to keep child c > <a> > <b> > <c>fdfdsf</c> > </b> > <b> > <c>fdfdsf</c> > </b> > </a> Use: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="*[not(descendant-or-self::c)]"/> </xsl:stylesheet> Cheers, Dimitre Novatchev | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
