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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:11:51+00:00 2026-05-31T22:11:51+00:00

I am trying to retrieve First Unique set of 2 attributes. I am looking

  • 0

I am trying to retrieve First Unique set of 2 attributes.

I am looking for each student name with his first unique group. If for a student first group is already taken for any student, next unique group should be listed. I have posted my XML and expected result XML.

I need XSLT statements to get this result (Version 1.0). Thanks.

Here’s my xml structure

<Socrates>
<Student name='Aristotle' group='1' />
<Student name='Aristotle' group='2' />
<Student name='Aristotle' group='3' />
<Student name='Aristotle' group='4' />

<Student name='Plato' group='1' />
<Student name='Plato' group='2' />
<Student name='Plato' group='3' />

<Student name='Xenophon' group='4' />
<Student name='Xenophon' group='5' />
<Student name='Xenophon' group='6' />

<Student name='Critias' group='1' />
<Student name='Critias' group='2' />
<Student name='Critias' group='3' />    
<Student name='Critias' group='4' />
<Student name='Critias' group='5' />
<Student name='Critias' group='6' />
   </Socrates>

Result XML

<Socrates>
    <Student name='Aristotle' group='1' />
<Student name='Plato' group='2' />
<Student name='Xenophon' group='4' />
<Student name='Critias' group='3' />
</Socrates>
  • 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-31T22:11:53+00:00Added an answer on May 31, 2026 at 10:11 pm

    Another slightly different approach (although not necessarily a better approach) is to pass a parameter to each student match which contains a comma-delimited of group attributes that have already been output. Every time you match a student, you check whether their group is in his parameter, and if not output the student, and get the next one, appending the current group to the parameter.

    Here is the XSLT, which I have commented to try and explain things better

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output indent="yes"/>
    
       <xsl:template match="Socrates">
          <Socrates>
             <xsl:apply-templates select="Student[1]"/>
          </Socrates>
       </xsl:template>
    
       <xsl:template match="Student">
          <!-- Parameter containin comma-delimited list of currently output groups -->
          <xsl:param name="groupList" select="','" />
          <xsl:choose>
             <!-- Has the group already been output? -->
             <xsl:when test="contains($groupList, concat(',', @group, ','))">
                <!-- If so, move on to next student record -->
                <xsl:apply-templates select="following-sibling::Student[1]">
                   <xsl:with-param name="groupList" select="$groupList" />
                </xsl:apply-templates>
             </xsl:when>
             <!-- Group has not already been output -->
             <xsl:otherwise>
                <!-- Output the record -->
                <xsl:copy-of select="." />
    
                <!-- Get the next student with a different name -->
                <xsl:apply-templates select="following-sibling::Student[@name!=current()/@name][1]">
                   <xsl:with-param name="groupList" select="concat($groupList, @group, ',')" />
                </xsl:apply-templates>
             </xsl:otherwise>
          </xsl:choose>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <Socrates>
       <Student name="Aristotle" group="1" />
       <Student name="Plato" group="2" />
       <Student name="Xenophon" group="4" />
       <Student name="Critias" group="3" />
    </Socrates>
    

    Note that this does assume the student elements are always ordered by name in the input XML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying retrieve user name from the code through graph api, the below
I am trying to retrieve the first two characters of a link's title attribute,
I am trying to retrieve date from an email. At first it's easy: message
I am trying to retrieve a set of values from database and assigned it
While working on my first app in Hibernate. While trying to retrieve a User
I'm trying to retrieve the first couple of capital letters from a string in
I am a beginner to MySQL and Im trying to retrieve a name for
I have this code. I am trying to retrieve just the text first program.
I am trying to retrieve data from a page which first requires to log
I am trying to retrieve a meta tag (Tag name=Generator) using Jsoup parser in

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.