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

Re: Exclusions in XPATH

Subject: Re: Exclusions in XPATH
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 21 Nov 2002 15:24:53 +0000
xpath exclude child
Hi Robin,

> XSL:
>                 <xsl:template match="A">
>                         <xsl:for-each
> select="./*[1]//*[not(*)]|./*[1]//@*[not(*)]">   
>                                 <xsl:value-of select="name()"/> 
>                                 <xsl:if test="position()!=last()">;</xsl:if>
>
>                         </xsl:for-each> 
>                 <xsl:apply-templates/> 
>         </xsl:template>
>
> Question 1: Can I get both attribute-names and element-names more
> easily in the select or does it have to be like I have it above ?

You can probably simplify the expression you're using to select the
elements and attributes to:

  .//*[not(*)] | .//@*

I say probably because (a) your path only looks at the descendants of
the first child of the <A> element, whereas the above looks at all
descendants of the <A> element and (b) your path wouldn't pick the <B>
element if it only held text, whereas mine would.
  
> If I only know the element-names A and F
>
> Question 2: How can I exclude the descendants of element F from the
> select ? Output would then be C;E;W. I've tried various combinations
> but either end up with all-or-nothing.

I think that the easiest way would be to add a filter to the
expression to only select those nodes that do not have the <F> element
as an ancestor:

  (.//*[not(*)] | .//@*)[not(ancestor::F)]

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.