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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:43:49+00:00 2026-05-27T09:43:49+00:00

I have got below XSLT which working for single grouping, however I need to

  • 0

I have got below XSLT which working for single grouping, however I need to have multiple grouping for my xml below:

XSLT1.0:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:strip-space elements="*"/>
  <xsl:output indent="yes"/>
  <xsl:variable name="linkURL" select="'/system/ASPX/Link.aspx?ID='"/>
  <xsl:template match="*">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="node()"/>
      <xsl:if test="self::navigation">
        <node GroupTitle="{//@GroupTitle[1]}" GroupCode="{//@GroupCode[1]}" url="{$linkURL}{//@GroupID[1]}">
          <nodes>
            <xsl:apply-templates select="node()" mode="group"></xsl:apply-templates>
          </nodes>
        </node>        
      </xsl:if>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*[normalize-space(@GroupCode) and not(*[not(normalize-space(@GroupCode))])]"/>

  <xsl:template match="node[normalize-space(@GroupCode)]" mode="group">
    <xsl:copy>    
      <xsl:apply-templates select="@*" mode="group"/>   
      <xsl:apply-templates select="node()" mode="group"/>      
    </xsl:copy>
  </xsl:template>

  <xsl:template match="node" mode="group">     
    <xsl:apply-templates select="node()" mode="group"/>
  </xsl:template>

  <xsl:template match="*" mode="group"/>

  <xsl:template  match="@*" mode="group">
    <xsl:attribute name="{name()}">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <!-- node attributes to be deleted have an empty template each -->
  <xsl:template match="@GroupTitle" mode="group"/>
  <xsl:template match="@GroupCode" mode="group"/>
  <xsl:template match="@GroupID" mode="group"/>
</xsl:stylesheet>

Part of XML:

<?xml version="1.0" encoding="utf-16"?>
<navigation path="/english">
    <resources>
        <Copyright>© 2011 mysite. All Rights Reserved.</Copyright>
    </resources>
    <node title="Root" id="tcm:233-38288-4" url="/">
        <node title="030. Plan &amp;amp; Book" id="tcm:233-38446-4" url="/plan_book/plan_and_book.aspx" indexpage="tcm:233-192249-64" compTitle="mysite Online Booking and Planning" imageSrcOn="/Preview/mysiteglobal/english/images/plan_book_highlight_tcm233-343461.gif" imageSrcOff="/Preview/mysiteglobal/english/images/plan_book_tcm233-343460.gif" imageSrcSelected="/Preview/mysiteglobal/english/images/plan_book_active_tcm233-343462.gif" imageSrcSelectedOn="/Preview/mysiteglobal/english/images/plan_book_highlight_tcm233-343461.gif" accessKey="P" GroupTitle="Plan and Book" GroupCode="PB" GroupID="tcm:234-458296">
            <node title="010. Search for a Flight" id="tcm:233-38911-4" url="/IBE.aspx" linktype="ibe" compTitle="Make a Booking" linksection="IBE" accessKey="1"/>
        </node> 
        <node title="035. Business Rewards" id="tcm:233-58061-4" url="/business_rewards/business_rewards.aspx" indexpage="tcm:233-358352-64" compTitle="Business Rewards" imageSrcOn="/Preview/mysiteglobal/english/images/business_rewards_highlight_tcm233-324549.gif" imageSrcOff="/Preview/mysiteglobal/english/images/business_rewards_tcm233-324548.gif" imageSrcSelected="/Preview/mysiteglobal/english/images/business_rewards_active_tcm233-324551.gif" imageSrcSelectedOn="/Preview/mysiteglobal/english/images/business_rewards_highlight_tcm233-324549.gif" authentication="sme-guest" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
        </node> 
        <node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/mysiteglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/mysiteglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/mysiteglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/mysiteglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
            <node title="080. The mysite High Street" id="tcm:233-59871-4" url="/Skywards/the_mysite_high_street/the_mysite_high_street.aspx" indexpage="tcm:233-346057-64" compTitle="The mysite High Street"/>
            <node title="090. Log In" id="tcm:233-92637-4" url="https://www.skywards.com/index.aspx" indexpage="tcm:233-636665-64" linktype="external" compTitle="Log In"/>
            <node title="100. Login" id="tcm:233-93287-4" url="/Skywards/skywardLogin/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
            <node title="110. Logout" id="tcm:233-93288-4" url="/Skywards/skywardLogout/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
        </node>
    </node>
</navigation>   

In above xml you will find that there are two type of GroupCode=”PB” and GroupCode=”SB”, The above XSLT code is doing only one grouping, but there can be lots of GroupCode in the xml and according to that my grouping will done. For above part XML I am looking below output:

<?xml version="1.0" encoding="UTF-8"?>
<navigation path="/english">
    <resources>
        <Copyright>© 2011 mysite. All Rights Reserved.</Copyright>
    </resources>
    <node title="Root" id="tcm:233-38288-4" url="/">
        <node title="030. Plan &amp;amp; Book" id="tcm:233-38446-4" url="/plan_book/plan_and_book.aspx" indexpage="tcm:233-192249-64" compTitle="mysite Online Booking and Planning" imageSrcOn="/Preview/mysiteglobal/english/images/plan_book_highlight_tcm233-343461.gif" imageSrcOff="/Preview/mysiteglobal/english/images/plan_book_tcm233-343460.gif" imageSrcSelected="/Preview/mysiteglobal/english/images/plan_book_active_tcm233-343462.gif" imageSrcSelectedOn="/Preview/mysiteglobal/english/images/plan_book_highlight_tcm233-343461.gif" accessKey="P" GroupTitle="Plan and Book" GroupCode="PB" GroupID="tcm:234-458296">
            <node title="010. Search for a Flight" id="tcm:233-38911-4" url="/IBE.aspx" linktype="ibe" compTitle="Make a Booking" linksection="IBE" accessKey="1"/>
        </node>
        <node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/mysiteglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/mysiteglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/mysiteglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/mysiteglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
            <node title="080. The mysite High Street" id="tcm:233-59871-4" url="/Skywards/the_mysite_high_street/the_mysite_high_street.aspx" indexpage="tcm:233-346057-64" compTitle="The mysite High Street"/>
            <node title="090. Log In" id="tcm:233-92637-4" url="https://www.skywards.com/index.aspx" indexpage="tcm:233-636665-64" linktype="external" compTitle="Log In"/>
        </node>
    </node>
    <node GroupTitle="Plan and Book" GroupCode="PB" url="/system/ASPX/Link.aspx?ID=tcm:234-458296">
        <nodes>
            <node title="030. Plan &amp;amp; Book" id="tcm:233-38446-4" url="/plan_book/plan_and_book.aspx" indexpage="tcm:233-192249-64" compTitle="mysite Online Booking and Planning" imageSrcOn="/Preview/mysiteglobal/english/images/plan_book_highlight_tcm233-343461.gif" imageSrcOff="/Preview/mysiteglobal/english/images/plan_book_tcm233-343460.gif" imageSrcSelected="/Preview/mysiteglobal/english/images/plan_book_active_tcm233-343462.gif" imageSrcSelectedOn="/Preview/mysiteglobal/english/images/plan_book_highlight_tcm233-343461.gif" accessKey="P"/>
        </nodes>    
    </node> 
    <node GroupTitle="Skywards and Business Rewards" GroupCode="SB" url="/system/ASPX/Link.aspx?ID=tcm:233-358296">
            <node title="035. Business Rewards" id="tcm:233-58061-4" url="/business_rewards/business_rewards.aspx" indexpage="tcm:233-358352-64" compTitle="Business Rewards" imageSrcOn="/Preview/mysiteglobal/english/images/business_rewards_highlight_tcm233-324549.gif" imageSrcOff="/Preview/mysiteglobal/english/images/business_rewards_tcm233-324548.gif" imageSrcSelected="/Preview/mysiteglobal/english/images/business_rewards_active_tcm233-324551.gif" imageSrcSelectedOn="/Preview/mysiteglobal/english/images/business_rewards_highlight_tcm233-324549.gif" authentication="sme-guest">
            </node>
            <node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/mysiteglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/mysiteglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/mysiteglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/mysiteglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S">
                <node title="100. Login" id="tcm:233-93287-4" url="/Skywards/skywardLogin/"/>
                <node title="110. Logout" id="tcm:233-93288-4" url="/Skywards/skywardLogout/"/>
            </node>
        </nodes>
    </node>
</navigation>
  • 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-27T09:43:50+00:00Added an answer on May 27, 2026 at 9:43 am

    Here is the complete full solution for above issue.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:variable name="linkURL" select="'/system/ASPX/Link.aspx?ID='"/>
    
        <xsl:strip-space elements="*"/>
        <xsl:output indent="yes"/>
    
         <!-- Key for Group Code attributes -->
        <xsl:key name="node" match="node" use="@GroupCode"/>
    
        <xsl:template match="*">
            <xsl:copy>
                <xsl:apply-templates select="@*" mode="group"/>
                <xsl:apply-templates select="node()"/> 
    
                <!-- use muenchian for that -->
                <xsl:if test="self::navigation">
                    <xsl:for-each select="node/node[generate-id() = generate-id(key('node', @GroupCode)[1])]">
                        <xsl:variable name="this-group-code" select="@GroupCode"/>
                        <node GroupTitle="{@GroupTitle}" GroupCode="{@GroupCode}" Url="{$linkURL}{@GroupID}">
                            <nodes>
                                <!-- push out all the nodes that have this particular group code -->
                                <xsl:apply-templates select="ancestor::navigation/node/node[@GroupCode = $this-group-code]" mode="group"></xsl:apply-templates>
                            </nodes>
                        </node>
                    </xsl:for-each>
                </xsl:if>
            </xsl:copy>
        </xsl:template>
    
        <!-- this template deletes all node that have a group code and no children that don't have a group code -->
        <xsl:template match="*[normalize-space(@GroupCode) and not(*[not(normalize-space(@GroupCode))])]"/>
    
        <!-- in mode group: copy all node that have a group code-->
        <xsl:template match="node[normalize-space(@GroupCode)]" mode="group">
            <xsl:copy>
                <xsl:apply-templates select="@*" mode="group"/>
                <xsl:apply-templates select="node()" mode="group"/>
            </xsl:copy>            
        </xsl:template>
    
        <xsl:template match="node" mode="group">
            <xsl:apply-templates select="node()" mode="group"/>
        </xsl:template>
    
        <!-- group mode: remove all other elements (not specified in higher up templates) -->
        <xsl:template match="*" mode="group"/>
    
        <!-- in mode group, copy all attributes (except those that have a more specific template match with other instructions -->
        <xsl:template  match="@*" mode="group">
            <xsl:attribute name="{name()}">
                <xsl:value-of select="."/>
            </xsl:attribute>
        </xsl:template>
    
        <!-- node attributes to be deleted have an empty template each -->
        <xsl:template match="@GroupTitle" mode="group"/>
        <xsl:template match="@GroupCode" mode="group"/>
        <xsl:template match="@GroupID" mode="group"/>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got below xml format file called ResourceData.xml . <?xml version=1.0 encoding=utf-8 ?>
I am using XSLT and XML. I have got below XML. <documentCountryInformation> <countryCode>US</countryCode> <countryName>United
I have got the XML below, which is stored in string type variable, and
I have got below given XML output: <?xml version=1.0?> <navigation path=/english> <resources> <Copyright>© 2009
i have got below code which is working fine: public abstract class Beverage {
So far i have got the code below which works lovely when trying an
I have below xml and I am using VBSript to generate it. <?xml version=1.0?>
I have got below xml in my string and I am using c# 2.0
I have got below code in which I am taking html and then reading
I have got html as below <a href= data-href=/somefile.php?id=10&refcode=/test.php>Hello</a> and I need to replace

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.