[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Copying most of an XML document

Subject: Re: Copying most of an XML document
From: david_n_bertoni@xxxxxxxxxx
Date: Mon, 22 Aug 2005 18:56:49 -0700
copying xml document
> Here is my magnolia tree - I need it copied exactly but I want to remove
> every caterpillar. Unfortunately it is infested with caterpillars
> throughout.

This is a very common question -- I swear it was even asked last week. You 
want to use the identity transformation and modify it slightly:

http://www.w3.org/TR/xslt#copying


<?xml version="1.0" encoding="UTF-8"?>

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

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

<xsl:template match="caterpillar" />

</xsl:stylesheet>

This assume that you want to remove every "caterpillar" element along with 
its descendants.

> 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.

All you really need to know is the names of the elements and/or attributes 
you _don't_ want to keep.

Dave

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.