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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:55:07+00:00 2026-05-21T05:55:07+00:00

I have a xml like below. Source XML: <?xml version=1.0 encoding=Windows-1252?> <XML> <Attributes> <Attribute>

  • 0

I have a xml like below.

Source XML:

<?xml version="1.0" encoding="Windows-1252"?>
<XML>
  <Attributes>
    <Attribute>
      <Name>Collection</Name>
      <Value />
    </Attribute>
    <Attribute>
      <Name>A</Name>
      <Value>Testing</Value>
    </Attribute>
    <Attribute>
      <Name>B</Name>
      <Value>Blank</Value>
    </Attribute>
    <Attribute>
      <Name>C</Name>
      <Value>11</Value>
    </Attribute>
    <Attribute>
      <Name>D</Name>
      <Value>NA</Value>
    </Attribute>
    <Attribute>
      <Name>A</Name>
      <Value>Testing1</Value>
    </Attribute>
    <Attribute>
      <Name>B</Name>
      <Value>Red</Value>
    </Attribute>
    <Attribute>
      <Name>C</Name>
      <Value>12</Value>
    </Attribute>
    <Attribute>
      <Name>D</Name>
      <Value>NAT</Value>
    </Attribute>
  </Attributes>
</XML>

From the above xml how I can I do this. I only want to group them in groups of 4. So first 4 (in the source xml) element where /attribute/Name=’A’ – /attribute/Name=’D’ will be in the first group. and next 4 where /attribute/Name=’A’ – /attribute/Name=’D’ will be in the second group …. like below

Thanks in Advance

Output

 <Collection name="Collection" >
           <ComplexAttr>
                  <Attr name="A" value="Testing" />
                  <Attr name="B" value="Blank" />
                  <Attr name="C" value="11" />
                  <Attr name="D" value="NA" />
           </ComplexAttr>
           <ComplexAttr >
                  <Attr name="A" value="Testing1" />
                  <Attr name="B" value="Red" />
                  <Attr name="C" value="12" />
                  <Attr name="D" value="NA" />
           </ComplexAttr>
    </Collection>
  • 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-21T05:55:07+00:00Added an answer on May 21, 2026 at 5:55 am

    This is a FAQ. See my link in the comments to your question. Here is a stylesheet tailored to your input and desired output:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <!--  the number of items to include in each group -->
        <xsl:variable name="group" select="4" />
        <xsl:template match="/">
            <Collection name="Collection">
                <xsl:apply-templates
                    select="XML/Attributes/Attribute[not(Name='Collection')]
                                                    [position() mod $group = 1]" />
            </Collection>
        </xsl:template>
        <xsl:template match="Attribute" mode="inner">
            <Attr name="{Name}" value="{Value}" />
        </xsl:template>
        <xsl:template match="Attribute">
            <ComplexAttr>
                <xsl:apply-templates
                    select=".|following-sibling::Attribute[position() &lt; $group]"
                    mode="inner" />
            </ComplexAttr>
        </xsl:template>
    </xsl:stylesheet>
    

    Produces:

    <Collection name="Collection">
        <ComplexAttr>
            <Attr name="A" value="Testing" />
            <Attr name="B" value="Blank" />
            <Attr name="C" value="11" />
            <Attr name="D" value="NA" />
        </ComplexAttr>
        <ComplexAttr>
            <Attr name="A" value="Testing1" />
            <Attr name="B" value="Red" />
            <Attr name="C" value="12" />
            <Attr name="D" value="NAT" />
        </ComplexAttr>
    </Collection>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XML File like that <?xml version=1.0 encoding=utf-8 ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName>
I have XML with a value like the following: <products> <product id=1 name=All Products>
I have an XML document something like ::: <?xml version=1.0 encoding=utf-8?> <?mso-application progid=Excel.Sheet?> <Workbook
Greetings! I have some XML like this: <Root> <MainSection> <SomeNode>Some Node Value</SomeNode> <SomeOtherNode>Some Other
I have an xml file like this: <root> <item> <name>one</name> <status>good</status> </item> <item> <name>two</name>
So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
I have normally hand written xml like this: <tag><?= $value ?></tag> Having found tools
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <details> ... <address1>Test&amp;Address</address1> ... </details> When
Let's say I have some XML like this <channel> <item> <title>This is title 1</title>
Greetings! I have some XML like this: <Root> <AlphaSection> . . . </AlphaSection> <BetaSection>

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.