xsl-list
[Top] [All Lists]

Re: Copying most of an XML document

2005-08-22 18:56:49
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>