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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:20:15+00:00 2026-06-03T10:20:15+00:00

I am working over sorting the Grand Parent based on a field in Father.

  • 0

I am working over sorting the Grand Parent based on a field in Father. The source file looks like

<Root>
    <AllData>
        <Data_not_to_be_sorted>
            <Additional_data1>
                <Some_test_data1/>
                <Some_test_data2/>
            </Additional_data1>
        </Data_not_to_be_sorted>
        <RealData>
            <Some_data1/>
            <Some_data2/>
            <GrandFather>
                <Data_required_as_it_is></Data_required_as_it_is>
                    <Father>
                        <Value>4</Value>
                        <Name>name in 4</Name>
                    </Father>
            </GrandFather>
            <GrandFather>
                <Data_required_as_it_is></Data_required_as_it_is>
                <Father>
                    <Value>3</Value>
                    <Name>name in 3</Name>
                </Father>
            </GrandFather>
        </RealData>
        <RealData>
            <Some_data1/>
            <Some_data2/>
            <GrandFather>
                <Data_required_as_it_is></Data_required_as_it_is>
                <Father>
                    <Value>2</Value>
                    <Name>name in 2</Name>
                </Father>
            </GrandFather>
            <GrandFather>
                <Data_required_as_it_is></Data_required_as_it_is>
                <Father>
                    <Value>1</Value>
                    <Name>name in 1</Name>
                </Father>
            </GrandFather>
        </RealData>
    </AllData>
</Root>

The XSLT code, I am using is as below:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@* | node()">
<xsl:copy>
   <xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>



<xsl:template match="RealData">
<xsl:copy>
<xsl:apply-templates select="Data_required_as_it_is"></xsl:apply-templates>
<xsl:apply-templates select="GrandFather">
<xsl:sort select="Father/Value" data-type="number"/>
</xsl:apply-templates>

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

The code is working well…My query is – Can I write a generic line for

Data_required_as_it_is. Imagine a situation where I have 20 different xml tags for “Data_required_as_it_is” so either I need write all of them manually or just write them in a generic way…

The output of the code is as below:

<Root>
    <AllData>
        <Data_not_to_be_sorted>
            <Additional_data1>
                <Some_test_data1/>
                <Some_test_data2/>
            </Additional_data1>
        </Data_not_to_be_sorted>
        <RealData>
            <Some_data1/>
            <Some_data2/>
            <GrandFather>
                <Data_required_as_it_is></Data_required_as_it_is>
                    <Father>
                        <Value>3</Value>
                        <Name>name in 3</Name>
                    </Father>
            </GrandFather>
            <GrandFather>
                <Data_required_as_it_is></Data_required_as_it_is>
                <Father>
                    <Value>4</Value>
                    <Name>name in 4</Name>
                </Father>
            </GrandFather>
        </RealData>
        <RealData>
            <Some_data1/>
            <Some_data2/>
            <GrandFather>
                <Data_required_as_it_is></Data_required_as_it_is>
                <Father>
                    <Value>1</Value>
                    <Name>name in 1</Name>
                </Father>
            </GrandFather>
            <GrandFather>
                <Data_required_as_it_is></Data_required_as_it_is>
                <Father>
                    <Value>2</Value>
                    <Name>name in 2</Name>
                </Father>
            </GrandFather>
        </RealData>
    </AllData>
</Root>
  • 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-03T10:20:16+00:00Added an answer on June 3, 2026 at 10:20 am
    <xsl:template match="RealData">
          <xsl:copy>
              <xsl:apply-templates select="Data_required_as_it_is"></xsl:apply-templates>
              <xsl:apply-templates select="GrandFather">
                  <xsl:sort select="Father/Value" data-type="number"/>
              </xsl:apply-templates>
          </xsl:copy>
      </xsl:template>
    

    One could use a more generic code like this:

    <xsl:template match="RealData">
        <xsl:copy>
            <xsl:apply-templates>
                <xsl:sort select="self::GrandFather/Father/Value" data-type="number"/>
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>
    

    Note: This will sort any any non-GrandFather node before any GrandFather node and will do the specified sorting of GrandFather elements by their Father/Value elements.

    In case it is desired that the non-GrandFather elements remain interspersed within the GrandFather elements, this can also be accomplished — ask another question if interested.

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

Sidebar

Related Questions

I'd like to get a tcp/ip connection working over the internet. I already have
Are there any geo-location api services like hostip.info that working over https Free services
I am confused over getting and clearing when working in Microsoft C. Like when
I have the jQuery UI sorting functionality working fine, but I would also like
A new user of Tortoise SVN, working over source control. I have a Visual
I need to get the free Google charts working over SSL without any security
I am working on porting over a database from a custom MSSQL CMS to
I am working through the SDL tutorials over at http://lazyfoo.net/SDL_tutorials/index.php and I'm stuck on
I am working with Naive Bayesian classifier over PHP ( http://www.xhtml.net/php/PHPNaiveBayesianFilter ) And there's
I'm working on converting some NSURLConnection code over to AFNetworking and I'm seeing a

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.