Re: [xsl] Value-of, copy-of

Subject: Re: [xsl] Value-of, copy-of
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Thu, 28 Feb 2002 09:36:06 +0100
Mike Ferrando <mikeferrando@xxxxxxxxx> wrote:
> I would like to exclude some elements from my copy-of output.

Well, Wendell gave you already a solution for your specific
problem.

However, it could also be handled as special case of the more
general problem "How do i copy a node tree with small changes?"
(this is actually a FAQ).

The general solution is to start out with the generic copy
template
  <xsl:template match="node()|@*">
   <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
   </xsl:copy>
  </xsl:template>
and then override it with templates for the "small changes",
for example in your case "do nothing for C1007 and C1010
elements":
  <xsl:template match="C1007|C1010"/>
You have to be careful, this would also delete these elements
elsewhere, if you want to do this only in a specific context
you could write
  <xsl:template match="C1001/C1007|C1001/C1010"/>
(delete only if they are a child of C1001)
or, more general
  <xsl:template match="C1001//C1007|C1001//C1010"/>
(delete only if they are a descendant of C1001)

You see, this approach is easier to extend, but bear in mind that
Wendells tailored solution might have a noticable performance
advantage.

Regards
J.Pietschmann

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


Current Thread