Re: [xsl] Match node() with exception

Subject: Re: [xsl] Match node() with exception
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 31 Aug 2004 09:53:01 +0100
Hi Karl,

> This is not working for me:
>
> <xsl:apply-templates select="node()[not(/SchemaVersion)]"/>
>
> I have the node "SchemaVersion" which I care to NOT display. What am
> I doing wrong?

You are selecting all the nodes that do not live in a document where
<SchemaVersion> is the root node. The path "/SchemaVersion" returns a
node when the <SchemaVersion> element is the root node. The expression
"not(/SchemaVersion)" returns true when there isn't such a node.

Given that the <SchemaVersion> element is a child of the current node
at the point you're using the <xsl:apply-templates> instruction, you
should use:

  <xsl:apply-tempaltes select="node()[not(self::SchemaVersion)]" />

self::SchemaVersion selects the node itself if it is a <SchemaVersion>
element. "not(self::SchemaVersion)" returns true only if the context
node isn't a <SchemaVersion> element. So
"node()[not(self::SchemaVersion)]" selects only those nodes that
aren't, themselves, <SchemaVersion> elements.

Alternatively, you could select all nodes with:

  <xsl:apply-templates select="node()" />

or, since the select attribute defaults to "node()", simply:

  <xsl:apply-templates />

and then have a template that does nothing when the <SchemaVersion>
element is processed:

<xsl:template match="SchemaVersion" />

Cheers,

Jeni

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

Current Thread