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: Tue, 12 Apr 2005 11:16:07 -0700
Thank you, thank you, thank you Michael, Mukul and Aron for your replies.

Thanks for the explanation about node sets and result tree fragments. That is certainly confusing for me!

The big revelation to me here is that I can do this:

<xsl:variable name="subset">
 <xsl:apply-templates select="a" mode="subset"/>
</xsl:variable>

Then still be able to do this:

<xsl:apply-templates select="exslt:node-set($subset)" />

I was under the impression that I could only use $subset this way if I had defined it using this form:

<xsl:variable name="subset" select="some XPATH expression" />

(If I remember correctly, $subset would be worthless to me if I did something like this:
<xsl:variable name="subset">
 <xsl:value-of select="some XPATH expression" />
<xsl:variable>
which I thought generalized to anything of the form:
<xsl:variable name="subset">
 -- anything here --
</xsl:variable>
but that does not appear to be the case!)

My real application is much more complicated that the example I provided, involving multiple documents, but it now works the way I desired and I have a new tool to use. Thank you all for your kind help.

- Rush

Michael Kay wrote:

The example that you've given suggests that you do actually want to create a
new tree that is a selective copy of the original tree. The way to do this
is to walk the original tree applying templates. If a node is to be copied
into the new tree, you apply the identity template, if it is to be removed,
you apply an empty template, and of course you can also have templates that
modify selected elements. So it looks something like this:

<xsl:variable name="subset">
 <xsl:apply-templates select="a" mode="subset"/>
</xsl:variable>

Current Thread