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

Re: Excluding a complete branch while identity copying

Subject: Re: Excluding a complete branch while identity copying
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 10 Oct 2008 13:57:04 -0400
Re:  Excluding a complete branch while identity copying

You'll be pleased to know that your application is about the easiest conceivable task for a near-identity transform.

Start with the identity template:

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

And then simply add a template to match the elements you want to discard, which does nothing with the elements it matches:

<xsl:template match="Evens | Squares"/>

-- and you're done. (Well, except for running and testing.)

This "Evens | Squares" template overrides the general-purpose copying template for the elements it matches.

Since it does nothing with the matched elements, nothing resembling them or their contents appears in the output. The identity template matches and copies everything else.

The arrangement of elements in the input doesn't matter since template matching doesn't concern itself directly with this, but simply reflects the source data in its given order, unless you do something to force some reordering.

If this raises questions about the XSLT processing model (why does this work?), so much the better, as it's also an excellent opportunity to study up on this and learn more about XSLT always works.


At 01:44 PM 10/10/2008, you wrote:
I want to be able to copy a complete XML instance as/is except for
[say] some specific parts of the input tree. I thought immediately of
using an identity transform and specifying copy, but how to remove
those pesky sub-trees :-

Say this was my input :-


and I want to copy everything to output except <Evens> and <Squares>.

Lets also assume that the order of the input is undefined, so Evens
and Squares may/may not be in the positions I have shown above,
although I can assume that they are both children of <Numbers>.
Further, I don't know what all the children of Evens and Squares are
called I just know I don't want them.

Whats the easiest way of accomplishing this ?

many thanks


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

Current Thread


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.
First Name
Last Name
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.