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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:53:05+00:00 2026-05-17T02:53:05+00:00

I have the following XML structure: <node name=A> <node name=B> <node name=C/> <node name=D/>

  • 0

I have the following XML structure:

<node name="A">
  <node name="B">
    <node name="C"/>
    <node name="D"/>
    <node name="E"/>
  </node>
  <node name="D"/>
  <node name="E"/>
</node>

I need to get all the leaf nodes. I use //node[not(node)] to get those. Now I need to remove duplicates by leaving elements that are deeper in hierarchy. How do I do that?

  • 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-17T02:53:06+00:00Added an answer on May 17, 2026 at 2:53 am

    This 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:variable name="vallLeaves" select="//node()[not(node())]"/>
    
     <xsl:template match="/">
    $vallLeaves:
         <xsl:copy-of select="$vallLeaves"/>
    
    $vallDistinctLeaves:    
         <xsl:for-each select="$vallLeaves">
           <xsl:if test=
           "generate-id()
            =
             generate-id($vallLeaves[@name
                                    =
                                     current()/@name
                                   ]
                                      [1]
                       )
         ">
             <xsl:copy-of select="."/>
           </xsl:if>
         </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <node name="A">
      <node name="B">
        <node name="C"/>
        <node name="D"/>
        <node name="E"/>
      </node>
      <node name="D"/>
      <node name="E"/>
    </node>
    

    produces the wanted, correct result:

    $vallLeaves:
         <node name="C"/>
    <node name="D"/>
    <node name="E"/>
    <node name="D"/>
    <node name="E"/>
    
    $vallDistinctLeaves:    
         <node name="C"/>
    <node name="D"/>
    <node name="E"/>
    

    II. XSLT 2.0 Solution:

    <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:variable name="vallLeaves" select="//node()[not(node())]"/>
        <xsl:variable name="vallDistinctLeaves" as="element()*">
          <xsl:for-each-group select="$vallLeaves" group-by="@name">
           <xsl:sequence select="."/>
          </xsl:for-each-group>
        </xsl:variable>
    
     <xsl:template match="/">
    $vallLeaves:
         <xsl:sequence select="$vallLeaves"/>
    
    $vallDistinctLeaves:    
         <xsl:sequence select="$vallDistinctLeaves"/>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the same XML document (above), the same correct results are produced:

    $vallLeaves:
         <node name="C"/>
    <node name="D"/>
    <node name="E"/>
    <node name="D"/>
    <node name="E"/>
    
    $vallDistinctLeaves:    
         <node name="C"/>
    <node name="D"/>
    <node name="E"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xml with the following structure: <NODES> <NODE> <NAME> </NAME> <IMG> </IMG>
I have the following simple XML structure that has to be parsed: <Nodes> <Node
I have a XML structure like the following: <Root> <Node Name=File System> <Node Name=C:\Windows\System32\drivers\etc\hosts>
I have the following XML structure: <agencies> <city> <name>New York</name> <address>Street A, 101</address> <phone>111-222-333</phone>
I have an XML file in the following structure. <NewDataSet> <markers> <name>name text</name> <desc>desc
I have the following XML structure: <row> <field name=Id>1</field> <field name=AreaId>1</field> <field name=Name>ת&quot;א</field> </row>
I have an xml file with following structure: <table name=tblcats> <row> <Id>3680</Id> <Industry>Associations</Industry> <ParentId>1810</ParentId>
I have an xml file with following structure: <table name=tblcats> <row> <Id>3680</Id> <Industry>Associations</Industry> <ParentId>1810</ParentId>
I have XML with the following structure, for example <root> <node flag=false/> <node flag=true/>
I have a huge bunch of XML files with the following structure: <Stuff1> <Content>someContent</name>

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.