Re: [xsl] How to create a node set that excludes some descendant elements?

Subject: Re: [xsl] How to create a node set that excludes some descendant elements?
From: Rush Manbert <rush@xxxxxxxxxxx>
Date: Mon, 11 Apr 2005 17:34:10 -0700
More info (sorry I didn't put it in the first post)

Rush Manbert wrote:

I want to create a global variable that contains the result tree fragment contained within element <c>, with the following restrictions:
I only want to include the first <y> element that is contained within <c>, no matter where it occurs. There may be no <y> elements present.
I want to exclude all <z> elements that are contained within <c>, no matter where they occur. Again, there may be none present.


I have tried many variations on the select portion of the variable definition. I can filter the immediate children of <c>, OR the second level children, etc., but I can't seem to come up with anything that handles <y> and <z> appearing at any depth in the descendant tree.

Some things I have tried:
<xsl:variable name="set" select="/a/b/c/*[((name() != 'y') and (name() != 'z'))] | /a/b/c//y[1]" />


<xsl:variable name="set" select="/a/b/c/descendant::*[((name() != 'y') and (name() != 'z'))] | /a/b/c//y[1]" />

Then I tried to just exclude <z> at any level:
<xsl:variable name="set" select="/a/b/c/descendant::*[not(self::z)]" />
but that only excludes <z> elements that are children of <c>.

I'm using xsltproc, built with libxml 2.6.19 and libxslt 1.1.14

- Rush

Current Thread