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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:10:27+00:00 2026-06-10T16:10:27+00:00

Firstly I am aware of this question: XSLT: Loop selecting two elements at a

  • 0

Firstly I am aware of this question: XSLT: Loop selecting two elements at a time

However I have not found it to work due to the element structure or I just fail with using mod, one of the two.

<input>
  <node>
    <id>1</id>
    <value>3</value>
  </node>
  <node>
    <id>1</id>
    <value>3</value>
  </node>
  <node>
    <id>1</id>
    <value>3</value>
  </node>
  <node>
    <id>1</id>
    <value>3</value>
  </node>
  <node>
    <id>2</id>
    <value>4</value>
  </node>
  <node>
    <id>2</id>
    <value>4</value>
  </node>
  <node>
    <id>2</id>
    <value>4</value>
  </node>
  <node>
    <id>2</id>
    <value>4</value>
  </node>
</input>

I have the following layout of XML which has the following structure:
– Nodes of the same ID will ALWAYS be grouped together
– There will always be four nodes to one ID

I wish to be able to select the four nodes of one ID at a time and loop through each group of four, so that I can manipulate the data into one output line.

What would be the best way to approach this?

  • 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-06-10T16:10:29+00:00Added an answer on June 10, 2026 at 4:10 pm

    This XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:key name="keyByID" match="node" use="id"/>
    
    <xsl:template match="/">
        <output>
            <xsl:apply-templates/>
        </output>
    </xsl:template>
    
    <xsl:template match="input">
        <xsl:for-each select="node[generate-id()=generate-id(key('keyByID',id)[1])]">
            <block>
                <id>
                    <xsl:value-of select="id"/>
                </id>
                <value>
                    <xsl:value-of select="value"/>
                </value>
            </block>
        </xsl:for-each>
    </xsl:template>
    
    
    </xsl:stylesheet>
    

    applied to your Input XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <input>
    <node>
        <id>1</id>
        <value>3</value>
    </node>
    <node>
        <id>1</id>
        <value>3</value>
    </node>
    <node>
        <id>1</id>
        <value>3</value>
    </node>
    <node>
        <id>1</id>
        <value>3</value>
    </node>
    <node>
        <id>2</id>
        <value>4</value>
    </node>
    <node>
        <id>2</id>
        <value>4</value>
    </node>
    <node>
        <id>2</id>
        <value>4</value>
    </node>
    <node>
        <id>2</id>
        <value>4</value>
    </node>
    </input>
    

    gives this grouped Output XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <output>
    <block>
        <id>1</id>
        <value>3</value>
    </block>
    <block>
        <id>2</id>
        <value>4</value>
    </block>
    </output>
    

    The output is grouped by <id>. Is that what you are looking for? I am not sure. This Muenchian Grouping just simpliefies your structure.

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

Sidebar

Related Questions

Firstly, please don't dismiss this question - I'm aware it's an ugly situation but
Firstly, I'm aware of this question , but I don't believe I'm asking the
Firstly, thanks for taking the time to read and possibly comment on this question.
Firstly, very sorry if this is not a true stackoverflow question. But it's something
Firstly I'm completely aware of this message and why it happens normally. It's not
Firstly sorry if this is a common question but I couldn't find anything on
Firstly, I know this [type of] question is frequently asked, so let me preface
Firstly I realise that this is a familiar question, it seems to pop up
Firstly, whilst I'm aware that gzipping HTML would probably have as much (more?) of
Firstly appologies for the poor title, not sure how to explain this in one

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.