[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: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 21 Nov 2002 11:14:43 -0500
xpath exclude nodes
Robin,

At 09:41 AM 11/21/2002, you wrote:
XPATH help appreciated !

 XML:
<A>
  <B>
    <C>101</C>
      <D>
        <E W="XYZ">0204268270</E>
           <F>
              <G>Versicherungsstr. 1</G>
              <H>Offenburg</H>
           </F>
        </E>
       </D>
   </B>
</A>

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>


This gives me output of: C;E;W;G;H


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 ?

Well, since attributes never have children you could say


select=" *[1]//*[not(*)] | *[1]//@*]"

which is a *little* easier.

It gets leaf node descendants of the first child element, plus all attributes on the first child or its descendants. Is this what you want? If you want only attributes on the leaf nodes that'll be "*[1]//*[not(*)] | *[1]//*[not(*)/@*", but in that case I'd think it'd be better first to select the leaves, then in a template get their attributes.

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.

You can exclude nodes that have an F ancestor by grouping with () and qualifying the group with another predicate:


select="(*[1]//*[not(*)] | *[1]//@*)[not(ancestor::F)]"

Cheers,
Wendell


___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_ "Thus I make my own use of the telegraph, without consulting the directors, like the sparrows, which I perceive use it extensively for a perch." -- Thoreau


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.