xsl-list
[Top] [All Lists]

RE: Copying most of an XML document

2005-08-23 01:16:24
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(_at_)castingthevoid(_dot_)com] 
Sent: 23 August 2005 02:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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


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





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