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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:05:32+00:00 2026-05-27T05:05:32+00:00

I have got below given XML output: <?xml version=1.0?> <navigation path=/english> <resources> <Copyright>© 2009

  • 0

I have got below given XML output:

    <?xml version="1.0"?>
    <navigation path="/english">
      <resources>
        <Copyright>© 2009 mysite. All Rights Reserved.</Copyright>
      </resources>
      <node title="010. Terms and Conditions" id="tcm:233-242834-64" url="termscondition.aspx" compTitle="Terms and Conditions"/>
        <node title="Root" id="tcm:233-38288-4" url="/">
            <node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/english/Images/skywards_on_tcm233-191728.gif" imageSrcOff="/english/Images/skywards_off_tcm233-191727.gif" imageSrcSelected="/english/Images/skywards_sel_tcm233-191730.gif" imageSrcSelectedOn="/english/Images/skywards_on2_tcm233-191729.gif" accessKey="S" Group="SB">   
                <node title="010. Membership Tiers" id="tcm:481-38882-4" url="/Skywards/membership_tiers/membership_tiers.aspx" indexpage="tcm:481-194317-64" compTitle="Membership Tiers"/>
                <node title="020. Earning Miles" id="tcm:481-38883-4" url="/Skywards/earning_miles/earning_miles.aspx" indexpage="tcm:481-194318-64" compTitle="Earning Skywards Miles"/>
                <node title="030. Travel Rewards" id="tcm:481-38884-4" url="/Skywards/travel_rewards/travel_rewards.aspx" indexpage="tcm:481-194320-64" compTitle="Travel Rewards"/>                 
            </node>
            <node title="H030. Search" id="tcm:233-38483-4" url="/search/search.aspx" indexpage="tcm:233-214259-64" compTitle="Search" localTitle="Search" accessKey="3" Group="SB"/>
            <node title="H010. Homepage" id="tcm:233-192367-64" url="/index.aspx" localTitle="Home" accessKey="0" Group="Home"/>
            <node title="H020. Skyward Homepage" id="tcm:233-143367-64" url="/index.aspx" localTitle="Home" accessKey="0" Group="Home"/>
        </node>
        <node title="footer">
            <node title="F010. 000. Sitemap" id="tcm:233-192374-64" url="/sitetools/sitemap.aspx" accessKey="4" compTitle="Sitemap"/>
            <node title="F060. Accessibility" id="tcm:233-192369-64" url="/sitetools/accessibility.aspx" compTitle="Accessibility Statement"/>
            <node title="F030. Operational Updates" id="tcm:233-192370-64" url="/sitetools/operational_updates.aspx" compTitle="Operational Updates"/>
            <node title="F050. Privacy Policy" id="tcm:233-192371-64" url="/sitetools/privacy_policy.aspx" compTitle="Privacy Policy"/>
            <node title="F040. Terms &amp; Conditions" id="tcm:233-192449-64" url="/sitetools/terms_and_conditions.aspx" compTitle="Terms &amp; Conditions"/>
        </node>
    </navigation>

Now want to write an xslt which will group the nodes on the basis of attribute “Group” with their value and add them in seperate node so that my ouput will be as given below:

<?xml version="1.0"?>
<navigation path="/english">
  <resources>
    <Copyright>© 2009 mysite. All Rights Reserved.</Copyright>
  </resources>
  <node title="010. Terms and Conditions" id="tcm:233-242834-64" url="termscondition.aspx" compTitle="Terms and Conditions"/>
    <node title="Root" id="tcm:233-38288-4" url="/">
        <node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/english/Images/skywards_on_tcm233-191728.gif" imageSrcOff="/english/Images/skywards_off_tcm233-191727.gif" imageSrcSelected="/english/Images/skywards_sel_tcm233-191730.gif" imageSrcSelectedOn="/english/Images/skywards_on2_tcm233-191729.gif" accessKey="S" Group="SB">   
        </node>
        <node title="H030. Search" id="tcm:233-38483-4" url="/search/search.aspx" indexpage="tcm:233-214259-64" compTitle="Search" localTitle="Search" accessKey="3" Group="SB"/>
        <node title="H010. Homepage" id="tcm:233-192367-64" url="/index.aspx" localTitle="Home" accessKey="0" Group="Home"/>
        <node title="H020. Skyward Homepage" id="tcm:233-143367-64" url="/index.aspx" localTitle="Home" accessKey="0" Group="Home"/>
    </node>
    <node title="footer">
        <node title="F010. 000. Sitemap" id="tcm:233-192374-64" url="/sitetools/sitemap.aspx" accessKey="4" compTitle="Sitemap"/>
        <node title="F060. Accessibility" id="tcm:233-192369-64" url="/sitetools/accessibility.aspx" compTitle="Accessibility Statement"/>
        <node title="F030. Operational Updates" id="tcm:233-192370-64" url="/sitetools/operational_updates.aspx" compTitle="Operational Updates"/>
        <node title="F050. Privacy Policy" id="tcm:233-192371-64" url="/sitetools/privacy_policy.aspx" compTitle="Privacy Policy"/>
        <node title="F040. Terms &amp; Conditions" id="tcm:233-192449-64" url="/sitetools/terms_and_conditions.aspx" compTitle="Terms &amp; Conditions"/>
    </node>
    <node GroupTitle="SB">
        <nodes>
            <node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/english/Images/skywards_on_tcm233-191728.gif" imageSrcOff="/english/Images/skywards_off_tcm233-191727.gif" imageSrcSelected="/english/Images/skywards_sel_tcm233-191730.gif" imageSrcSelectedOn="/english/Images/skywards_on2_tcm233-191729.gif" accessKey="S" Group="SB">   
            </node>
            <node title="H030. Search" id="tcm:233-38483-4" url="/search/search.aspx" indexpage="tcm:233-214259-64" compTitle="Search" localTitle="Search" accessKey="3" Group="SB"/>
        </nodes> 
    </node>   
    <node GroupTitle="Home">
        <nodes>
            <node title="H010. Homepage" id="tcm:233-192367-64" url="/index.aspx" localTitle="Home" accessKey="0" Group="Home"/>
            <node title="H020. Skyward Homepage" id="tcm:233-143367-64" url="/index.aspx" localTitle="Home" accessKey="0" Group="Home"/>
        </nodes> 
    </node>     
</navigation>

Please suggest!!

  • 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-27T05:05:33+00:00Added an answer on May 27, 2026 at 5:05 am

    This stylesheet should do the trick:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    
        <!-- Key for Group attributes -->
        <xsl:key name="nodesByGroups" match="node[@Group]" use="@Group" />
    
        <xsl:template match="/*">
    
            <!-- Making shallow copy of root element -->
            <xsl:copy>
    
                <!-- Making deep copy of all child elements, as well as any root element attributes -->
                <xsl:copy-of select="*|@*" />
    
                <!-- Calling the template for grouping on the root element -->
                <xsl:call-template name="group" />
    
            </xsl:copy>
    
        </xsl:template>
    
        <xsl:template name="group">
    
            <!-- Apply the technique known as Muenchian grouping -->
            <xsl:for-each select="//node[generate-id() = generate-id(key('nodesByGroups', @Group)[1])]/@Group">
                <xsl:variable name="group" select="." />
                <xsl:element name="node">
                    <xsl:attribute name="GroupTitle"><xsl:value-of select="$group" /></xsl:attribute>
                    <xsl:element name="nodes">
                        <xsl:copy-of select="/*//node[@Group = $group]" />
                    </xsl:element>
                </xsl:element>
            </xsl:for-each>
    
        </xsl:template>
    
    </xsl:stylesheet>
    

    The second template makes use of a technique known as Muenchian grouping. It can be a little complex at first to understand should you not be familiar with XSLT and XPath, but once you get it, it becomes a great tool. There’s a thorough explanation of it here.

    EDIT: you could write the second template like this, if you find it more legible:

    <xsl:template name="group">
    
        <!-- Apply the technique known as Muenchian grouping -->
        <xsl:for-each select="//node[generate-id() = generate-id(key('nodesByGroups', @Group)[1])]/@Group">
            <xsl:variable name="group" select="." />
            <node GroupTitle="{$group}">
                <nodes>
                    <xsl:copy-of select="/*//node[@Group = $group]" />
                </nodes>
            </node>
        </xsl:for-each>
    
    </xsl:template>
    

    EDIT 2: okay, I hope this will do what you need:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    
        <!-- Key for Group attributes -->
        <xsl:key name="nodesByGroups" match="node[@Group]" use="@Group" />
    
        <xsl:template match="/*">
    
            <!-- Making shallow copy of root element -->
            <xsl:copy>
    
                <!-- Apply templates on all the child elements/attributes as appropriate -->
                <xsl:apply-templates select="node()|@*" />
    
                <!-- Calling the template for grouping on the root element -->
                <xsl:call-template name="group" />
    
            </xsl:copy>
    
        </xsl:template>
    
        <xsl:template match="node()|@*">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*" />
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="node">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*" />
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="node[@Group]">
            <xsl:copy>
                <xsl:apply-templates select="@*" />
            </xsl:copy>
        </xsl:template>
    
        <xsl:template name="group">
    
            <!-- Apply the technique known as Muenchian grouping -->
            <xsl:for-each select="//node[generate-id() = generate-id(key('nodesByGroups', @Group)[1])]/@Group">
                <xsl:variable name="group" select="." />
                <xsl:element name="node">
                    <xsl:attribute name="GroupTitle"><xsl:value-of select="$group" /></xsl:attribute>
                    <xsl:element name="nodes">
                        <xsl:apply-templates select="/*//node[@Group = $group]" />
                    </xsl:element>
                </xsl:element>
            </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

I am using JQuery. I have got one link as given below: <li><a href=http://staging/english/Skywards/skywards.aspx
I have got the XML below, which is stored in string type variable, and
I have got table as given below in database: Name Grade Subject Ami HD
So far i have got the code below which works lovely when trying an
I have got some code to load an assembly and get all types, which
I tried the following code in LINQPad and got the results given below: List<string>
my build.XML is given below. <property name=src.dir value=src/> <property name=lib.dir value=lib/> <property name=build.dir value=build/>
i have a group tag as given below but i am getting the error:'Scalar
I have got below code in c#. SqlConnection conn = new SqlConnection(Data Source=MANOJ-PC\\SQLEXPRESS;Initial Catalog=master;Integrated
I have got below JQuery where I am performing the .load function. $(.load-fragment).each(function() {

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.