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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:03:44+00:00 2026-05-19T06:03:44+00:00

I need help in sorting an XML file based on xml nodes and ONE

  • 0

I need help in sorting an XML file based on xml nodes and ONE more thing is i have to place their comment tags corresponding to that node.

For Example: Input XML File is

<?xml version="1.0" encoding="UTF-8"?>
<!-- catalog main -->
<catalog>
 <!-- first book id -->
 <book id="bk101">
  <!-- author name 1 -->
  <author>Gambardella, Matthew</author>
  <!-- title name 1 -->
  <title>XML Developer's Guide</title>
  <genre>Computer</genre>
  <!-- price 1 -->
  <price>44.95</price>
  <publish_date>2000-10-01</publish_date>
  <description>An in-depth look at creating applications 
      with XML.</description>
 </book>
 <Book id="bk102">
  <author>Ralls, Kim</author>
  <title>Midnight Rain</title>
  <genre>Fantasy</genre>
  <price>5.95</price>
  <publish_date>2000-12-16</publish_date>
  <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
 </Book>


 <!-- languages -->
 <Languages>
  <!-- java comment -->
  <java>Galos, Mike</java>
  <c>Visual Studio 7: A Comprehensive Guide</c>
  <!-- dotnet comment -->
  <dotnet>Computer</dotnet>
  <!-- description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
 </Languages>

 <!-- ABC book -->
 <ABC>
  <!-- ABC author -->
  <author1>Galos, Mike</author1>
  <title1>Visual Studio 7: A Comprehensive Guide</title1>
  <!-- ABC genre -->
  <genre1>Computer</genre1>
  <price1>49.95</price1>
  <publish_date>2001-04-16</publish_date>
  <!-- ABC description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
 </ABC>
 <!-- ABC1 book -->
 <abc1>
  <!-- ABC1 author -->
  <author1>Galos, Mike</author1>
  <title1>Visual Studio 7: A Comprehensive Guide</title1>
  <!-- ABC1 genre -->
  <genre1>Computer</genre1>
  <price1>49.95</price1>
  <publish_date>2001-04-16</publish_date>
  <!-- ABC1 description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
 </abc1>
</catalog>

EXPECTED OUTPUT XML FILE SHOULD BE:

<?xml version="1.0" encoding="UTF-8"?>
<!-- catalog main -->
<catalog>
 <!-- ABC book -->
 <ABC>
  <!-- ABC author -->
  <author1>Galos, Mike</author1>
  <!-- ABC description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
  <!-- ABC genre -->
  <genre1>Computer</genre1>
  <price1>49.95</price1>
  <publish_date>2001-04-16</publish_date>
  <title1>Visual Studio 7: A Comprehensive Guide</title1>
 </ABC>
 <!-- ABC1 book -->
 <abc1>
  <!-- ABC1 author -->
  <author1>Galos, Mike</author1>
  <!-- ABC1 description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
  <!-- ABC1 genre -->
  <genre1>Computer</genre1>
  <price1>49.95</price1>
  <publish_date>2001-04-16</publish_date>
  <title1>Visual Studio 7: A Comprehensive Guide</title1>
 </abc1>
 <!-- first book id -->
 <book id="bk101">
  <!-- author name 1 -->
  <author>Gambardella, Matthew</author>
  <description>An in-depth look at creating applications 
      with XML.</description>
  <genre>Computer</genre>
  <!-- price 1 -->
  <price>44.95</price>
  <publish_date>2000-10-01</publish_date>
  <!-- title name 1 -->
  <title>XML Developer's Guide</title>
 </book>
 <Book id="bk102">
  <author>Ralls, Kim</author>
  <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
  <genre>Fantasy</genre>
  <price>5.95</price>
  <publish_date>2000-12-16</publish_date>
  <title>Midnight Rain</title>
 </Book>
 <!-- languages -->
 <Languages>
  <c>Visual Studio 7: A Comprehensive Guide</c>
  <!-- description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
  <!-- dotnet comment -->
  <dotnet>Computer</dotnet>
  <!-- java comment -->
  <java>Galos, Mike</java>
 </Languages>
</catalog>
  • 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-19T06:03:45+00:00Added an answer on May 19, 2026 at 6:03 am

    It seems I have resolved this issue with an additional implementation..
    Below is the new code:-

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:strip-space elements="*"/>
        <xsl:template match="*|@*">
            <xsl:copy-of select="preceding-sibling::node()[1]/self::comment()"/>
            <xsl:copy>
                <xsl:apply-templates select="@*"/>
                <xsl:apply-templates select="node()">
                    <xsl:sort select="name()"/>
                    <xsl:sort select="@*"/>
                </xsl:apply-templates>
            </xsl:copy>
        </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 need some help sorting out a CSS issue with my website, I have
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I have a regex call that I need help with. I haven't posted my
I need help sorting and counting instances of the words in a string. Lets
Hey all need a lil help sorting a loop for this table out, cant
I need help sorting [Time] data from in this array in php. For a
I made this function and need some help sorting out the logic flow. It
Sorting is giving me a hard time. I need help with an small example,
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I need help understanding some C++ operator overload statements. The class is declared like

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.