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

  • SEARCH
  • Home
  • 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 8240313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:26:58+00:00 2026-06-07T20:26:58+00:00

It should return all first occurrences for nodes with same name, even if the

  • 0

It should return all first occurrences for nodes with same name, even if the childs and attribbutes differ.

For example

<Data>
  <A>
    <X randomattr="1"/>
    <Y randomattr="1"/>
    <Z/>
  </A>
  <B>
    <X/>
    <X randomattr="3"/>
    <Z/>
  </B>
</Data>

It sould return 3 nodes, first X, Y and Z, because the following, will have a repeated name. Don’t mind if one of the X elements does not have randomattr or if another has a different value.

I dont want the distinct-values from name(), I want to return the whole node. Something like

/Data/*/*[distinct-values(name())]

I also know I can transverse all nodes with a double loop, but I am asking myyself if there is an easy one-liner or a function for this, or a special Xpath syntax like distinct[1]
Thank u!

  • 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-07T20:27:01+00:00Added an answer on June 7, 2026 at 8:27 pm

    I think this is what you might be looking for. Worked with some simple tests:

    • (Xpath 2.0) /Data/*/*[not((preceding-sibling::*/name(.)=name(.)) or (../preceding-sibling::*/*/name(.)=name(.)))]
    • (Xpath 1.0) /Data/*/*[not((name(preceding-sibling::*)=name(.)) or (name(../preceding-sibling::*/*)=name(.)))]

    After the request to make it work to any depth… I am unfamiliar with your schema, but from the example I’m assuming that the nodes you are looking for are the bottom level nodes. The following uses the descendant axes to search for nodes with no children while doing the name check.

    • /Data/descendant::*[not(name() = preceding::*[not(child::*)]/name())][not(child::*)]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running a query which should return all open questions along with the last update
It's my understanding that all three of these lines below should return an ARRAY
Should all linq queries which return an entity be surrounded with a try catch?
for example: <li class=list id=first-list></li> var li = document.getElementById(first-list); matchSelector(li, li.list); // this should
The following code should return me the average numbers the first five players did
My understanding is that count and length should return the same number for Ruby
The method below should return true for the first call, and false for any
I've implemented code that should return present location. First the code: public static double[]
func($name1) should return name1 Is it possible?
Left outer joins should return at least one row from the T1 table if

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.