RE: Copying most of an XML document
The classic design pattern for this a stylesheet that contains (a) an identity template <xsl:template match="*"> <xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy> </xsl:template> (b) an extra template for the elements you want to remove or modify <xsl:template match="caterpillar"/> Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Trevor Nicholls [mailto:trevor@xxxxxxxxxxxxxxxxxx] > Sent: 23 August 2005 02:20 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Copying most of an XML document > > Hello > > Given an original XML document that I need to process in > several different > ways I am finding the job much more difficult than it needs > to be, I think, > because the file contains a lot of "noise". I want to use XSL > to clean the > file up in a first pass so that it will be simpler to process > later on. > > Here is my magnolia tree - I need it copied exactly but I > want to remove > every caterpillar. Unfortunately it is infested with caterpillars > throughout. > > Basically I want to do something like copy every single node, > children and > attributes and all, but whenever I find (e.g.) an <a> node I > want to ignore > it. If I could somehow tell 'xsl:copy-of' what to ignore that > would be all I > needed (but I can't). If I knew the full structure of the file I could > create templates to match and replicate all the nodes I wanted to keep > without losing any of their attributes, but sadly this XML has been > generated by Framemaker (from unstructured original > documents) and there is > no document definition to work from. > > I'm hoping there is an XSL solution to this. > > Cheers > Trevor
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format