xsl-list
[Top] [All Lists]

Re: Match node() with exception

2004-08-31 01:53:01
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/



<Prev in Thread] Current Thread [Next in Thread>