Re: [xsl] Removing entire branches from a node-set

Subject: Re: [xsl] Removing entire branches from a node-set
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 10 Jan 2005 11:42:41 GMT
> but this just results in everything getting included in the node-set 
> several times

No, a set only ever contains one copy of each of its members. the set
{1,1,2,3} is the same set as {1,2,3}.

I think your mis-use of the terminology is confusing you. You don't want
to filter a node set (which means that you can't simply use Xpath)
you want to generate modified nodes (so you have to use XSLT).

If you have a node set $input corresonding to 
<root>
   <node>This node should always be included in the node-set</node>
   <node lang="en">This node should only be included in the <b>English</b> node-set</node>
   <node lang="de">This node should only be included in the <b>German</b> node-set</node>
</root>


then $input is a set of _one_ node, (/) the parent node of that root
element. If you use any XPath at all to select children of that node
then either it will select the element node with name root or it
won't. If it does select that element then the element will be unchanged
(it will still have all its original descendents, although these
descendents may or may not be in the node set).

You can generate a result tree in which every element satisfies
@lang='en' or not(@lang) by

<xsl:template match="*">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="*[not(@lang='en' or not(@lang))"/>

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread