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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:25:30+00:00 2026-05-25T22:25:30+00:00

Here is sample xml <Data version=2.0> <Group> <Item>3</Item> <Item>1</Item> <Item>2</Item> </Group> <Group> <Item>7</Item> <Item>5</Item>

  • 0

Here is sample xml

<Data version="2.0">
   <Group>
        <Item>3</Item>
        <Item>1</Item>
        <Item>2</Item>
   </Group>
   <Group>
        <Item>7</Item>
        <Item>5</Item>
   </Group>
</Data>

And for ordering nodes in Group by Item value I tried to use the following xsl:

  <xsl:template match="/Data">

    <xsl:apply-templates select="Group">
      <xsl:sort select="Item" />
    </xsl:apply-templates>

  </xsl:template>

But get only values, even without sorting:

    3
    1
    2

    7
    5

So the questions are: 1. why sorting not work 2. How to keep all nodes and keep structure of xml?

  • 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-25T22:25:32+00:00Added an answer on May 25, 2026 at 10:25 pm

    @Jim’s answer is basically correct.

    However, applied to a slightly more realistic XML document, such as this:

    <Data version="2.0">
       <Group>
            <Item>3</Item>
            <Item>1</Item>
            <Item>10</Item>
            <Item>2</Item>
       </Group>
       <Group>
            <Item>7</Item>
            <Item>5</Item>
       </Group>
    </Data>
    

    the result produced is clearly not what you want (10 comes before 2 and 3):

    <?xml version="1.0" encoding="utf-8"?>
    <Data version="2.0">
    
       <Group>
          <Item>1</Item>
          <Item>10</Item>
          <Item>2</Item>
          <Item>3</Item>
       </Group>
    
       <Group>
          <Item>5</Item>
          <Item>7</Item>
       </Group>
    
    </Data>
    

    Here is a correct solution (that is also slightly shorter):

    <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="Group">
      <Group>
       <xsl:apply-templates select="*">
        <xsl:sort data-type="number"/>
       </xsl:apply-templates>
      </Group>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the same XML document (above), the wanted, correct result is produced:

    <Data version="2.0">
       <Group>
          <Item>1</Item>
          <Item>2</Item>
          <Item>3</Item>
          <Item>10</Item>
       </Group>
       <Group>
          <Item>5</Item>
          <Item>7</Item>
       </Group>
    </Data>
    

    Explanation: Use of the data-type attribute of <xsl:sort> to specify that the sort keys value should be treated as number, not as (the default) string.

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

Sidebar

Related Questions

Here's my application-security.xml file: <?xml version=1.0 encoding=UTF-8?> <!-- - Sample namespace-based configuration - -
Here is a simple form I am using to send XML data in admin_xml.php
VS2008, .NET Framework 3.5 We're utilizing the WebEx Xml API. Here's a sample Xml
Here's sample model classes, which being use with Entity Framework Code First: public class
Here is sample data <table class=sparql border=1> <tr> <th>abstract</th></tr> <tr> <td> Cologne is Germany&#39;s
Data: Here is sample table(TableA) data ID StartTime EndTime 1 2012-03-22 06:00:00.000 2012-03-22 06:30:00.000
Here's the sample data: <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <customField1>Whatever</customField1> <customField2>Whatever</customField2> <customField3>Whatever</customField3>
I'd like to optimize the XSL transform below. I've included sample input data and
I have a simple Itemrenderer with the following code: <?xml version=1.0 encoding=utf-8?> <s:ItemRenderer xmlns:fx=http://ns.adobe.com/mxml/2009
Here are some sample records ID(UniqueIdentifier) UserId title description version parentid 8362AB94-946F-4092-97C2-ABD957CC2E20 3 title

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.