Re: Copying a portion of a subtree in its entirety including retaining the attribute and text info

Subject: Re: Copying a portion of a subtree in its entirety including retaining the attribute and text info
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 21 Nov 2000 14:58:47 +0000
Mike,

> Why am I not getting everything from 'Filter' down and why is it also
> returning items within Object2 when I'm only matching on 'Object1'. This
> is becoming extremely confusing for me.

I'm not sure why you're not getting a full copy of 'Filter', but the
reason that you're getting text from within Object2 is due to the way
the built-in templates work.

The built-in templates give arguably helpful default behaviour: they
ensure that templates are applied all the way down the document tree,
and they output any text that they find as is. Thus to ensure that
templates are *not* applied to Object2 and so on down the hierarchy
until you get to the text within it, which is then outputted, you need
to override this default behaviour.

You can do this in two ways.  Firstly, you can give a template that
says "when you see an Object2, do nothing" (an empty template):

<xsl:template match="Object2" />

Secondly, you can have something that matches a node higher up the
hierarchy (e.g. on the root node or document element) that says "only
apply templates to Object1":

<xsl:template match="Config">
  <xsl:apply-templates select="Object1" />
</xsl:template>

Of these, the latter is probably better because it stops the XSLT
Processor from having to search for templates to apply to Object2
(which can take time).  However the former option is sometimes more
practical when you want to apply templates to all except one
particular thing.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread