[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: How to create a node set that excludes some desce

Subject: RE: How to create a node set that excludes some descendant elements?
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Tue, 12 Apr 2005 03:09:35 +0000
xsl discard node
Rush, hopefully you'll find better answers, but here's my first pass. I modified the "identity transform" to filter out z and non-first y's. You'll have to tweak it to account for "contained within 'c'". You may wrap up in a variable as needed.

Also, I assume when you mean to discard <z> elements, you also mean to discard any of its descendents.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>

   <xsl:template match="node(  ) | @*">
     <xsl:if test="name() != 'z' and not (name() = 'y' and preceding::y)">
           <xsl:apply-templates select="@* | node(  )"/>




From: Rush Manbert <rush@xxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: How to create a node set that excludes some descendant elements?
Date: Mon, 11 Apr 2005 16:57:24 -0700

Hi all,

My first post here and I want to start by saying how much I appreciate the big FAQ, the Jeni site, etc. It has all helped me tremendously.

I can't find an answer to this one, though, so here goes...

My XML doc has this basic structure:
     <!-- This is the section of interest -->

The <c> element can contain any combination of elements <d> through <z>. Elements <y> and <z> have special uses.

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.

Later on in my stylesheet, I use exslt:node-set() on the variable and process the node set.

For instance, given this source:
   <g />
     <y />
     <z />
   <y />

I want the selection to contain this:
   <g />
     <y />

(<z> elements are gone, only the first <y> element remains.)

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.

I'm prepared to be humiliated by some obvious solution... Can anyone please help?


Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.