Re: [xsl] deep copy and exclude some nodes

Subject: Re: [xsl] deep copy and exclude some nodes
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 14 Jan 2003 09:47:16 +0000
Hi Joeri,

> I used
> <xsl:copy>
>   <xsl:copy-of select="@*"/>
>   <xsl:copy-of select="*[name() != 'field2']"/>
> <xsl:copy>
>
> But what when i need to remove more fields.
> I tried   <xsl:copy-of select="*[name() != 'field1' and name() !=
> 'field2']"/> but is not working.

Strange; I think that should work. You could use:

  <xsl:copy-of select="*[not(self::field1 or self::field2)]" />

(it's better to use self::field1 than name() = 'field1' because the
former is namespace-aware), but I think that in this case you should
probably apply templates to all the fields and then have empty
templates that filter out the fields that you don't want.

In other words, have an identity template like:

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

which will do the copying, and then have a template that does nothing
with field1 and field2 elements:

<xsl:template match="field1 | field2" />

Cheers,

Jeni

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


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


Current Thread