Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8259605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:54:13+00:00 2026-06-08T02:54:13+00:00

How to exclude specific descendants of a node? In this direction, the expression *[not(self::nodetag)]

  • 0

How to exclude specific descendants of a node? In this direction, the expression *[not(self::nodetag)] seems just to discriminate at a child level of the node, accepting all other descedants in the returned node set. I want a expression to select all under div but those nodes that are not a, see example below. The tree structure must remain the same.

The approach poste by @Dimitri Novatchev seems to be right but not for HAP implementation:

Using this example document:

<div>
  <span>
     <a>lala</a>
  </span>
</div>

The HAP would return the following structure with his suggested expression /div/descendant::node()[not(self::a)]

<div>
  <span>
     <a>lala</a>
  </span>
</div>
<span>
     <a>lala</a>
 </span>

If there would be another tag other than a nested on span, it would also return it as a separte tree, any one know about this strange behavior? Is it a HAP bug?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:54:15+00:00Added an answer on June 8, 2026 at 2:54 am

    I want a expression to select all under div but those nodes that are
    not a. The tree structure must remain the same.

    Use:

    /div/descendant::node()[not(self::a)]
    

    This selects any descendant of the top element div that (the descendant) is not an a.

    XSLT – based verification:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/">
      <xsl:for-each select="/div/descendant::node()[not(self::a)]">
        <xsl:value-of select="concat('&#xA;', position(), '. &quot;')"/>
        <xsl:copy-of select="."/>"
      </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <div>
        <span>
            <a>lala</a>
        </span>
    </div>
    

    the XPath expression is evaluated and all selected nodes are output with proper formatting to make them well-visible:

    1. "
        "
    
    2. "<span>
    
       <a>lala</a>
    
    </span>"
    
    3. "
            "
    
    4. "lala"
    
    5. "
        "
    
    6. "
    "
    

    As we can see, 6 nodes are selected — one span element, four whitespace-only text nodes and one non-whitespace-only text node — and none of them is an a.

    Update:

    In a comment the OP has clarified that he actually wants the XML document to be transformed into another, in which any a descendant of a div is omitted.

    Here is one such transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="div//a"/>
    </xsl:stylesheet>
    

    When this transformation is applied on the same XML document (above), the (wwhat I guess is) wanted result is produced:

    <div>
       <span/>
    </div>
    

    If we want to produce only the descendants of any div that has an a descendant, then we need almost the same transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="div[.//a]"><xsl:apply-templates/></xsl:template>
     <xsl:template match="div//a"/>
    </xsl:stylesheet>
    

    The result of this applied to the same XML document as above is:

    <span/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a regex somewhat like this: [match-word] ... [exclude-specific-word] ... [match-word]
I'd like to exclude Internet Explorer from using a specific CSS class. Is this
Is it possible to exclude specific files or folders from Build Deployment Package function
How do I exclude specific .dlls from Visual Studio 2003 C++ .NET? During release
Is it possible to exclude specific files (*.ai, *.psd) when pushing to certain repositories
I want to redirect non-www to www, and exclude a specific file (eg. testit.php).
I want to exclude a field using Dozer like this : <mapping> <class-a>com.core.model.Model</class-a> <class-b>com.core.model.ModelIS</class-b>
Can I exclude a specific id from update=:myComponent ? I have a larger page
Is it possible to exclude a specific database from streaming replication in Pg 9.1?
I want to extend the standard asp.net email regex validator to exclude a specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.