473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

XSL Sort Problem

11
I have an XML document that looks like the following:

Expand|Select|Wrap|Line Numbers
  1. <root name="PlanRepository">
  2.   <directory name="connoraj">
  3.     <directory name="single_run1">
  4.       <file>insidebox.txt</file>
  5.       <file>outsidebox.txt</file>
  6.       <directory name="SAFE_Input">
  7.         <file>leapseconds.txt</file>
  8.         <file>single_run.dat</file>
  9.         <directory name="LeoInputs">
  10.           <file>control_earth.txt</file>
  11.           <file>leo_sc_prop2.txt</file>
  12.         </directory>
  13.       </directory>
  14.       <directory name="SAFE_Output">
  15.         <file>single_run.aer.dat</file>
  16.         <file>single_run.control_files</file>
  17.         <file>single_run.dv.dat</file>
  18.         <file>single_run.est_pv.dat</file>
  19.         <file>single_run.host_ephem.e</file>
  20.         <file>single_run.host_inertial.dat</file>
  21.         <file>single_run.residuals.dat</file>
  22.         <file>single_run.tar_ephem.e</file>
  23.         <file>single_run.tar_inertial.dat</file>
  24.         <file>single_run.true_pv.dat</file>
  25.       </directory>
  26.     </directory>
  27.   </directory>
  28. </root>
  29.  
This type of schema repeats, but has a different number of files within each directory.

What I'm attempting to do is, within each directory, sort its respective files by their file extensions. The problem is, that in the "SAFE_Output" directory, each filename has 2 "."s in it, which is making a standard way of sorting very difficult. I have come across different types of solutions, but all either don't sort the SAFE_Output folder correctly or add extra files to the nodes.

Using the following XSL:
Expand|Select|Wrap|Line Numbers
  1.   <xsl:template match="root">
  2.     &lt;root name="PlanRepository"&gt;
  3.     <br/>
  4.     <xsl:apply-templates />
  5.     &lt;/root&gt;
  6.   </xsl:template>
  7.  
  8.   <xsl:template match="directory">
  9.     &lt;directory name="<xsl:value-of select="@name"/>"&gt;
  10.     <br/>
  11.     <xsl:choose>
  12.       <xsl:when test="@name = 'SAFE_Output'">
  13.         <xsl:for-each select="file">
  14.           <xsl:sort select="substring-after(substring-after(.,'.'),'.')" />
  15.           &lt;file&gt;<xsl:value-of select="."/>&lt;/file&gt;
  16.           <br/>
  17.         </xsl:for-each>
  18.       </xsl:when>
  19.       <xsl:otherwise>
  20.         <xsl:for-each select="file">
  21.           <xsl:sort select="substring-after(.,'.')" />
  22.           &lt;file&gt;<xsl:value-of select="."/>&lt;/file&gt;
  23.           <br/>
  24.         </xsl:for-each>
  25.       </xsl:otherwise>
  26.     </xsl:choose>
  27.     <xsl:apply-templates/>
  28.     &lt;/directory&gt;
  29.     <br/>
  30.   </xsl:template>
  31.  
it sorts the files by file extension, including the files in SAFE_Output, but for some reason adds an extra line of every filename after it goes through each file (Lines 6, 10, 14, 28). The result is:

Expand|Select|Wrap|Line Numbers
  1. <root name="PlanRepository">
  2.   <directory name="connoraj">
  3.     <directory name="single_run.dat.07-10-2007.01-50-22">
  4.       <file>insidebox.txt</file>
  5.       <file>outsidebox.txt</file>
  6.       insidebox.txtoutsidebox.txt
  7.       <directory name="SAFE_Input">
  8.         <file>single_run.dat</file>
  9.         <file>leapseconds.txt</file>
  10.         leapseconds.txtsingle_run.dat
  11.         <directory name="LeoInputs">
  12.           <file>control_earth.txt</file>
  13.           <file>leo_sc_prop2.txt</file>
  14.           control_earth.txtleo_sc_prop2.txt
  15.         </directory>
  16.       </directory>
  17.       <directory name="SAFE_Output">
  18.         <file>single_run.control_files</file>
  19.         <file>single_run.aer.dat</file>
  20.         <file>single_run.dv.dat</file>
  21.         <file>single_run.est_pv.dat</file>
  22.         <file>single_run.host_inertial.dat</file>
  23.         <file>single_run.residuals.dat</file>
  24.         <file>single_run.tar_inertial.dat</file>
  25.         <file>single_run.true_pv.dat</file>
  26.         <file>single_run.host_ephem.e</file>
  27.         <file>single_run.tar_ephem.e</file>
  28.         single_run.aer.datsingle_run.control_filessingle_run.dv.datsingle_run.est_pv.datsingle_run.host_ephem.esingle_run.host_inertial.datsingle_run.residuals.datsingle_run.tar_ephem.esingle_run.tar_inertial.datsingle_run.true_pv.dat
  29.       </directory>
  30.     </directory>
  31.   </directory>
  32. </root>
  33.  
Can anyone see what is causing this problem? Or know of a better way to figure this out?

Thanks
Jul 18 '07 #1
2 2155
jkmyoung
2,057 Expert 2GB
In your directory template you have this: <xsl:apply-templates/>
This gets applied to each of the files.
2 different ways to fix:
1. Change this to <xsl:apply-templates select="directory"/>
OR
2. Add an empty template to catch files. <xsl:template match="file"/>

both 1 line fixes.
Jul 18 '07 #2
ajc308
11
I used method #1 and it worked. Thanks so much for your hep and speedy response!
Jul 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

40
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the...
4
by: hall | last post by:
I accidently overloaded a static member function that I use as predicate in the std::sort() for a vector and ended up with a compiler error. Is this kind of overload not allowed for predicates and...
7
by: Ireneusz SZCZESNIAK | last post by:
I want to sort a vector with the std::sort function. There are two functions: one with two arguments, the other with three arguments. I am using the one with three arguments. I noticed that...
2
by: Joel | last post by:
I am having some problems compiling my code on Mandrake 10 with g++ (GCC 3.3.2). The problem seems to be in that I try to define a functor that compares two pointer objects, and use that functor to...
7
by: Stuart | last post by:
The stl::sort() that comes with Dev Studio 6 is broken (it hits the degenerate case in a common situation). I have a replacement. I would like to globally do "using namespace std; except use my...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
11
by: James P. | last post by:
Hello, I have a report with the Priority field is used as sort order and grouping. The problem is the data in this Priority field if sorted in ascending order is: High, Low, and Medium. How...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.