Hi All.
I have an xml something like this: - <?xml version="1.0" encoding="UTF-8"?>
-
<root>
-
<person>
-
<name>John</name>
-
<family name>Smith</family name>
-
</person>
-
<address>
-
<street>123</street>
-
<city>New York</city>
-
</address>
-
</root>
I want to sort only the first level. i.e.
have result like this: - <?xml version="1.0" encoding="UTF-8"?>
-
<root>
-
<address>
-
<street>123</street>
-
<city>New York</city>
-
</address>
-
<person>
-
<name>John</name>
-
<family name>Smith</family name>
-
</person>
-
</root>
address now comes before person, but the internal nodes, keep their order.
I want to sort it alphabetically using xslt file.
Any idea?
I appreciate your help.
Amichai
Hi,
I discussed this issue with a friend of mine, and he suggested me not do this sorting with xslt, and do it using C# sorting function instead.
Dormilich, thanks for the help, and for the good willing.
Sorting first level using xslt is no more needed for my task.
Have you all nice week.
Amichai.
7 2876
what does the <xsl:sort> give you?
Hi Dormilich,
I'm pretty novice with xslt, and the examples i've seen over the web, shows how to sort the entire xml, but no one (i've find) show how to sort only first level.
The xslt file i'm using looks like this: - <?xml version="1.0" encoding="utf-8" ?>
-
<!-- ex: set sw=2 ts=2 expandtab: -->
-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-
-
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
-
-
<xsl:template match="/">
-
<xsl:apply-templates />
-
</xsl:template>
-
<xsl:template match="@*|node()">
-
<xsl:copy>
-
<xsl:copy-of select="@*"/>
-
<!-- copy all attributes before applying templates to children only -->
-
<xsl:apply-templates >
-
<!-- First sort key: node name -->
-
<xsl:sort data-type="text" select="name()" order="ascending" case-order="upper-first" />
-
<!-- Second sort key: 'Name' property -->
-
<xsl:sort data-type="text" select="@Name" order="ascending" case-order="upper-first" />
-
</xsl:apply-templates>
-
-
</xsl:copy>
-
</xsl:template>
-
</xsl:stylesheet>
actually, i'm trying to sort with node Name and 'Name' attribute, but for simplifying the question (as the sort according to one key or more is not relevant) i'm asking only about 'sort first level' issue.
Thanks for your help.
Amichai.
looking at the provided xsl... why do you want to sort the XML? XML is used for data transfer, so a sort without intention behind does not make sense to me.
I need to sort a very large xml file (sized 60MB).
Currently i'm sorting it using the xslt file above. however this consumes a lot of memory (~700MB), and i'm afraid that when i get larger xml files (let's say 200MB sized), the sorting will fail the application with out of memory exception.
So the solution i thought about was to sort only one level at time, and to travel over the xml and sort each time the node and the children without descended.
What i'm asking is: is there a simple way doing this with xslt?
from what I know it is not specifically the sorting that requires that much memory, it is parsing and building the document tree itself that requires the memory. to work with very large XML files, you probably need a different parser model.
Hi,
I discussed this issue with a friend of mine, and he suggested me not do this sorting with xslt, and do it using C# sorting function instead.
Dormilich, thanks for the help, and for the good willing.
Sorting first level using xslt is no more needed for my task.
Have you all nice week.
Amichai.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: p0wer |
last post by:
Let's suppose I have this sample document:
<root>
<entry id="1"
<date>2003-08-03</date>
<param_1>5</param_1>
<param_2>10</param_2>
</entry>
<entry id="2">
...
|
by: mike |
last post by:
If I had a date in the format "01-Jan-05" it does not sort properly
with my sort routine:
function compareDate(a,b)
{
var date_a = new Date(a);
var date_b = new Date(b);
if (date_a < date_b)...
|
by: suzy |
last post by:
hello.
how can i sort data in a dataset? all the examples i have seen on msdn, etc
are sorting a dataview. this works fine, but i want to return the results
in xml and the dataview doesn't...
|
by: Mike P |
last post by:
I have just written my first page with a datagrid that allows ASC and
DESC sorting. But I want to know how I can get it so that the header
shows the type of sorting that has just been done on it...
|
by: Matthew Curiale |
last post by:
I am creating an app that lists clients of a company for management of
different attributes for that company. The first page is a listing of
the companies currently in the database. I have my...
|
by: =?Utf-8?B?TGFycnlS?= |
last post by:
I need some help with a multilevel sorting problem with the List<>.
I have a List<ItemToSort( see below ) that needs to be sorted in the
following manner:
Sort by Level1Id ( ok that was the easy...
|
by: Gilberto |
last post by:
Hello,
I have a report with some product information and i needed to create a NEW SORTING LEVEL with some TOTAL calculations which where located at the REPORT FOOTER, just so that they could be...
|
by: KevinADC |
last post by:
Introduction
In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
|
by: KevinADC |
last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
|
by: jrod11 |
last post by:
hi,
I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |