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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:49:59+00:00 2026-05-18T02:49:59+00:00

Let’s assume, you have the xml below. The goal is to group by FirstName

  • 0

Let’s assume, you have the xml below. The goal is to group by FirstName and export the Person into different xml files. Each output xml files should only contain up to X different FirstName.

Below is an example of the desired transformation with X = 3

XML input:

<People>
    <Person>             
        <FirstName>John</FirstName>             
        <LastName>Doe</LastName> 
    </Person> 
    <Person>             
        <FirstName>Jack</FirstName>             
        <LastName>White</LastName> 
    </Person>
    <Person>             
        <FirstName>Mark</FirstName>             
        <LastName>Wall</LastName> 
    </Person>
    <Person>             
        <FirstName>John</FirstName>             
        <LastName>Ding</LastName> 
    </Person> 
    <Person>             
        <FirstName>Cyrus</FirstName>             
        <LastName>Ding</LastName> 
    </Person>  
    <Person>             
        <FirstName>Megan</FirstName>             
        <LastName>Boing</LastName> 
    </Person>
</People>          

XML output 1 with 3 different FirstName

<People>
    <Person>             
        <FirstName>John</FirstName>             
        <LastName>Doe</LastName> 
    </Person> 
    <Person>             
        <FirstName>John</FirstName>             
        <LastName>Ding</LastName> 
    </Person>
    <Person>             
        <FirstName>Jack</FirstName>             
        <LastName>White</LastName> 
    </Person>
    <Person>             
        <FirstName>Mark</FirstName>             
        <LastName>Wall</LastName> 
    </Person>  
</People> 

XML output 2 with the 2 remaining FirstName

<People>
    <Person>             
        <FirstName>Cyrus</FirstName>             
        <LastName>Ding</LastName> 
    </Person>  
    <Person>             
        <FirstName>Megan</FirstName>             
        <LastName>Boing</LastName> 
    </Person>
</People> 

It seems to me that the muenchian grouping can be used along with the to produce multiple output files. However, the core question is where we can set a threshold in number of person before exporting to a new file?

  • 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-18T02:49:59+00:00Added an answer on May 18, 2026 at 2:49 am

    Here is an example of doing it in two steps with XSLT 2.0:

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="xs"
      version="2.0">
    
      <xsl:param name="n" as="xs:integer" select="3"/>
    
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="People">
        <xsl:variable name="groups" as="element(group)*">
          <xsl:for-each-group select="Person" group-by="FirstName">
            <group>
              <xsl:copy-of select="current-group()"/>
            </group>
          </xsl:for-each-group>
        </xsl:variable>
        <xsl:for-each-group select="$groups" group-by="(position() - 1) idiv $n">
          <xsl:result-document href="group{position()}.xml">
            <People>
              <xsl:copy-of select="current-group()"/>
            </People>
          </xsl:result-document>
        </xsl:for-each-group>
      </xsl:template>
    
    </xsl:stylesheet>
    

    I might try to convert to XSLT 1.0 and EXSLT later.

    [edit]
    Here is an attempt to translate into XSLT 1.0 and EXSLT:

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:exsl="http://exslt.org/common"
      extension-element-prefixes="exsl"
      exclude-result-prefixes="exsl"
      version="1.0">
    
      <xsl:param name="n" select="3"/>
    
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:key name="person-by-firstname" 
               match="Person"
               use="FirstName"/>
    
      <xsl:template match="People">
        <xsl:variable name="groups">
          <xsl:for-each select="Person[generate-id() = generate-id(key('person-by-firstname', FirstName)[1])]">
            <group>
              <xsl:copy-of select="key('person-by-firstname', FirstName)"/>
            </group>
          </xsl:for-each>
        </xsl:variable>
        <xsl:for-each select="exsl:node-set($groups)/group[(position() - 1) mod $n = 0]">
          <exsl:document href="groupTest{position()}.xml">
            <People>
              <xsl:copy-of select="Person | following-sibling::group[position() &lt; $n]/Person"/>
            </People>
          </exsl:document>
        </xsl:for-each>
      </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let assume we have two activities. A - main activity, that is home launcher
Let's suppose I have an XML file like this: <?xml version=1.0 encoding=ISO-8859-1?> <MIDIFile> <Event>
Let's say I have a large amount of files, say 20GB worth, all encrypted
Let's say you have different settings in development vs. production ( different options, different
Let's assume, I have some sequence, e.g. Fibonacci numbers, defined as a template: template
Let's say I have a method in java, which looks up a user in
Let me explain best with an example. Say you have node class that can
Let's say I have a table with a Color column. Color can have various

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.