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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:04:58+00:00 2026-05-13T23:04:58+00:00

Using the XSL: <?xml version=1.0 encoding=UTF-8?> <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:output method=xml/> <xsl:template

  • 0

Using the XSL:

<?xml version="1.0" encoding="UTF-8"?>
<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:output method="xml"/>
    <xsl:template match="/">
        <records>
            <record>
                <!-- Group record by bigID, for further processing -->
                <xsl:for-each-group select="records/record" group-by="bigID">
                    <xsl:sort select="bigID"/>
                    <xsl:for-each select="current-group()">
                        <!-- Create new combined record -->
                        <bigID>
                            <!-- <xsl:value-of select="."/> -->
                            <xsl:for-each select=".">
                                <xsl:value-of select="bigID"/>
                            </xsl:for-each>
                        </bigID>
                        <text>
                            <xsl:value-of select="text"/>
                        </text>
                    </xsl:for-each>
                </xsl:for-each-group>
            </record>
        </records>
    </xsl:template>
</xsl:stylesheet>

I’m trying to change:

<?xml version="1.0" encoding="UTF-8"?>
<records>
    <record>
        <bigID>123</bigID>
        <text>Contains text for 123</text>
        <bigID>456</bigID>
        <text>Some 456 text</text>
        <bigID>123</bigID>
        <text>More 123 text</text>
        <bigID>123</bigID>
        <text>Yet more 123 text</text>
    </record>
</records>

into:

<?xml version="1.0" encoding="UTF-8"?>
<records>
    <record>
        <bigID>123
            <text>Contains text for 123</text>
            <text>More 123 text</text>
            <text>Yet more 123 text</text>
        </bigID>
        <bigID>456
            <text>Some 456 text</text>
        </bigID>
    </record>
</records>

Right now, I’m just listing the grouped <bigID>s, individually. I’m missing the step after grouping, where I combine the grouped <bigID> nodes. My suspicion is that I need to use the “key” function somehow, but I’m not sure.

Thanks for any help.

  • 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-13T23:04:59+00:00Added an answer on May 13, 2026 at 11:04 pm

    Here is the wanted XSLT 2.0 transformation:

    <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
        <xsl:key name="kTextforId" match="text"
             use="preceding-sibling::bigID[1]"/>
    
      <xsl:template match="node()|@*">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="record">
       <record>
        <xsl:for-each-group select="bigID" group-by=".">
         <bigID>
           <xsl:sequence select="current-grouping-key()"/>
    
           <xsl:copy-of select=
           "key('kTextforId', current-grouping-key())"/>
         </bigID>
        </xsl:for-each-group>
       </record>
      </xsl:template>
    </xsl:stylesheet>
    

    When performed on the provided XML document, the wanted result is produced.

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

Sidebar

Related Questions

I have the following in xslt <?xml version=1.0 encoding=UTF-8?> <xsl:stylesheet version=2.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns:fn=http://www.w3.org/2005/02/xpath-functions
i have the following xslt sheet: <?xml version=1.0 encoding=UTF-8 ?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version=1.0> <xsl:variable
I'm using Xsl transformation to display an Xml data as Html. <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform
i have a xsl file as below: -------Begin------ <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet version=2.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform
i use the following XSLT by using XMLSpy: <?xml version=1.0 encoding=UTF-16?> <xsl:stylesheet version=2.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform
I'm trying to query an xml file using the following xslt: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform
I'm experimenting with XSLT2, using a stylesheet based on this answer: <xsl:stylesheet version=2.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform>
I have a style sheet like this <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:param
I've xml as below, <?xml version=1.0 encoding=utf-16 ?> <AllResidentAndUnitInfo xmlns:i=http://www.w3.org/2001/XMLSchema-instance i:type=ResidentsByUnitInfo xmlns=http://schemas.datacontract.org/2004/07/FSRSchema> <BillingAddresses> <BillingAddress>
Hello i have an XSLT that looks like so: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output omit-xml-declaration=yes

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.