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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:04:21+00:00 2026-05-22T12:04:21+00:00

how do i sort the elements based on CorporationID and group them.. I have

  • 0

how do i sort the elements based on “CorporationID” and group them..

I have an xml payload something like the below one …

 <corporationActions>
  <corporationAction>
    <ActionID>5530974</ActionID>
    <CorporationID>1044294</CorporationID>
    <ActionDate>2009-05-03</ActionDate>
    <ActionType>Articles of Organization2</ActionType>
    <ActionNotes></ActionNotes>
    <DocumentNumber>20110258775-68</DocumentNumber>
    <NumberofPages>4</NumberofPages>
  </corporationAction>
  <corporationAction>
    <ActionID>5530975</ActionID>
    <CorporationID>1044294</CorporationID>
    <ActionDate>2009-05-03</ActionDate>
    <ActionType>Miscellaneous</ActionType>
    <ActionNotes></ActionNotes>
    <DocumentNumber>20110258777-80</DocumentNumber>
    <NumberofPages>2</NumberofPages>
  </corporationAction>
</corporationActions>

i need to first sort the elements based on CorporationID and then group them if the CorporationID s are repeating.. like the below paylaod

<corporationActions>
    <corporationAction>
        <CorporationID>1044294</CorporationID>
        <corporationActionDetails>
            <ActionID>5530974</ActionID>
            <ActionDate>2009-05-03</ActionDate>
            <ActionType>Articles of Organization2</ActionType>
        </corporationActionDetails>
        <corporationActionDetails>
            <ActionID>5530975</ActionID>
            <ActionDate>2009-05-03</ActionDate>
            <ActionType>Miscellaneous</ActionType>
        </corporationActionDetails>
    </corporationAction>
</corporationActions>

Thanks & Regards,
anvv sharma

  • 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-22T12:04:22+00:00Added an answer on May 22, 2026 at 12:04 pm

    This is an XSLT 1.0 grouping (Muenchian method) solution, that is mostly in push-style using templates and no <xsl:for-each>:

    <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:key name="kcorpActByID" match="corporationAction"
      use="CorporationID"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*">
             <xsl:sort select="CorporationID" data-type="number"/>
           </xsl:apply-templates>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
     "corporationAction|CorporationID
     |ActionNotes|DocumentNumber|NumberofPages"/>
    
     <xsl:template match=
      "corporationAction
        [generate-id()
        =
         generate-id(key('kcorpActByID', CorporationID)[1])
         ]">
      <corporationAction>
       <xsl:copy-of select="CorporationID"/>
       <xsl:apply-templates mode="copy"
        select="key('kcorpActByID',CorporationID)" />
      </corporationAction>
     </xsl:template>
    
     <xsl:template match="corporationAction" mode="copy">
      <corporationActionDetails>
       <xsl:apply-templates/>
      </corporationActionDetails>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied to the provided XML document:

    <corporationActions>
      <corporationAction>
        <ActionID>5530974</ActionID>
        <CorporationID>1044294</CorporationID>
        <ActionDate>2009-05-03</ActionDate>
        <ActionType>Articles of Organization2</ActionType>
        <ActionNotes></ActionNotes>
        <DocumentNumber>20110258775-68</DocumentNumber>
        <NumberofPages>4</NumberofPages>
      </corporationAction>
      <corporationAction>
        <ActionID>5530975</ActionID>
        <CorporationID>1044294</CorporationID>
        <ActionDate>2009-05-03</ActionDate>
        <ActionType>Miscellaneous</ActionType>
        <ActionNotes></ActionNotes>
        <DocumentNumber>20110258777-80</DocumentNumber>
        <NumberofPages>2</NumberofPages>
      </corporationAction>
    </corporationActions>
    

    the wanted, correct result is produced:

    <corporationActions>
       <corporationAction>
          <CorporationID>1044294</CorporationID>
          <corporationActionDetails>
             <ActionID>5530974</ActionID>
             <ActionDate>2009-05-03</ActionDate>
             <ActionType>Articles of Organization2</ActionType>
          </corporationActionDetails>
          <corporationActionDetails>
             <ActionID>5530975</ActionID>
             <ActionDate>2009-05-03</ActionDate>
             <ActionType>Miscellaneous</ActionType>
          </corporationActionDetails>
       </corporationAction>
    </corporationActions>
    

    Do note: The added flexibility due to the use and overriding of the identity template. In contrast of <xsl:copy-of select="ActionID|ActionDate|ActionType"/> we use: <xsl:apply-templates/> and this assures that any of the children of the current node can be processed in any way we want (and further specify in separate templates).

    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:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="/*">
      <xsl:for-each-group select="corporationAction"
           group-by="CorporationID">
       <xsl:sort select="number(CorporationID)"/>
    
       <corporationAction>
        <xsl:sequence select="CorporationID"/>
        <xsl:apply-templates mode="copy"
         select="current-group()" />
       </corporationAction>
      </xsl:for-each-group>
     </xsl:template>
    
     <xsl:template match="corporationAction" mode="copy">
      <corporationActionDetails>
       <xsl:apply-templates/>
      </corporationActionDetails>
     </xsl:template>
    
      <xsl:template match=
     "corporationAction|CorporationID
     |ActionNotes|DocumentNumber|NumberofPages"/>
    </xsl:stylesheet>
    

    Do note: the simplified grouping using <xsl:for-each-group> and the current-group() function.

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

Sidebar

Related Questions

If I have a list of elements I would like to sort, Java offers
I have some simple jQuery written to sort some elements based on a numerical
I have a list of files I would like to sort based on the
I have a gridview and I need to sort its elements when the user
I have an array which i need to sort its elements by occurrence then
I currently use the sort function to sort my div elements based on the
I want to be able to sort elements based on an attribute in my
I have a group of fieldset elements within a form. I need to make
I am facing an issue where I need to sort elements based on different
I'm looking for a way to sort my elements, but it isn't as easy

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.