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 7558875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:29:15+00:00 2026-05-30T12:29:15+00:00

I am trying to select all the <set>erase</set> elements such that if two or

  • 0

I am trying to select all the <set>erase</set> elements such that if two or more elements have the <set>erase</set> in hierarchy (Ex: <b> and <d> both have <set>erase</set>) then only the element in parent node name has to be selected(ie <b> in this case).

Sample xml below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<a>
    <b>
        <set>erase</set>
        <d>
            <set>erase</set>
        </d>
    </b>

    <c>
        <x></x>
    </c>

    <e>
        <y>
            <set>erase</set>
            <q></q>
        </y>
        <z>
            <p>
                <set>erase</set>
            </p>
        </z>
    </e>
</a>

When I use the query = //set[contains(.,'erase')] I get all <set>erase</set> of nodesList b,d,y,p in result set.

I need help in framing the query to select <set>erase</set> of b , y and p.

  • 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-05-30T12:29:17+00:00Added an answer on May 30, 2026 at 12:29 pm

    Here is the same solution:

    One XPath expression that selects exactly the wanted elements is:

              //*[set[. = 'erase' and not(node()[2])]
                 and
                  not(ancestor::*
                         [set
                            [. = 'erase' and not(node()[2])]
                         ]
                      )
                  ]
    

    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:strip-space elements="*"/>
    
             <xsl:template match="/">
                 <xsl:for-each select=
                 "//*[set[. = 'erase' and not(node()[2])]
                     and
                      not(ancestor::*
                             [set
                                [. = 'erase' and not(node()[2])]
                             ]
                          )
                      ]">
    
                  <xsl:value-of select="name()"/>
                  <xsl:text>&#xA;</xsl:text>
                </xsl:for-each>
             </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <a>
        <b>
            <set>erase</set>
            <d>
                <set>erase</set>
            </d>
        </b>
        <c>
            <x></x>
        </c>
        <e>
            <y>
                <set>erase</set>
                <q></q>
            </y>
            <z>
                <p>
                    <set>erase</set>
                </p>
            </z>
        </e>
    </a>
    

    The contained XPath expression is evaluated and the names of the selected elements are output — correctly and as expected:

    b
    y
    p
    

    If you need to select the set children of the selected above elements, just append the above XPath expression with /set:

              //*[set[. = 'erase' and not(node()[2])]
                 and
                  not(ancestor::*
                         [set
                            [. = 'erase' and not(node()[2])]
                         ]
                      )
                  ]
                   /set
    

    Again, 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:strip-space elements="*"/>
    
             <xsl:template match="/">
                 <xsl:copy-of select=
                 "//*[set[. = 'erase' and not(node()[2])]
                     and
                      not(ancestor::*
                             [set
                                [. = 'erase' and not(node()[2])]
                             ]
                          )
                      ]
                       /set
                      "/>
             </xsl:template>
    </xsl:stylesheet>
    

    This transformation just evaluates the above XPath expression and copies to the output the correctly selected three set elements:

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

Sidebar

Related Questions

I'm trying to style all <select> elements that are a descendant of a <div>
In trying to select elements that have any attributes, the following throws a jQuery
in my user table i have two users when trying to select all users
What I'm trying is to get all users that don't have a value set
I'm trying to write some JavaScript for my website that will select all the
I'm trying to select a small set of records that match a patten I
I'm trying to select all dates between 2 dates. In the database I have
Using Linq, trying to select all records not in my local set fails: var
I am trying to select all the records from a sqlite db I have
I'm trying to select all <div> s with the same ID in jQuery. How

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.