473,320 Members | 1,846 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,320 software developers and data experts.

XSL Copy Problem

11
I'm attempting to sort the <file>s within each <directory> in my XML according to their file extension, then write out the resulting sorted data back to XML format. I had it working before, and when I opened up the file the next day, the XSL behaved completely different. I don't know if I accidentally changed something, but I can't see any problems with my code.

My Sample XML:

Expand|Select|Wrap|Line Numbers
  1. <root name="PlanRepository">
  2.   <directory name="connoraj">
  3.     <directory name="single_run.dat.07-23-2007.10-59-51">
  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.  
My XSL File:

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="root">
  2.     <xsl:copy>
  3.       <xsl:attribute name="name">PlanRepository</xsl:attribute>
  4.       <xsl:apply-templates/>
  5.     </xsl:copy>
  6.   </xsl:template>
  7.  
  8.   <xsl:template match="directory">
  9.     <xsl:copy>
  10.       <xsl:copy-of select="@name"/>
  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.             <xsl:copy-of select="."/>
  16.           </xsl:for-each>
  17.         </xsl:when>
  18.         <xsl:otherwise>
  19.           <xsl:for-each select="file">
  20.             <xsl:sort select="substring-after(.,'.')" />
  21.             <xsl:copy-of select="."/>
  22.           </xsl:for-each>
  23.         </xsl:otherwise>
  24.       </xsl:choose>
  25.       <xsl:apply-templates select="directory"/>
  26.     </xsl:copy>
  27.   </xsl:template>
  28.  
My resulting output:
Expand|Select|Wrap|Line Numbers
  1. insidebox.txtoutsidebox.txtsingle_run.datleapseconds.txtcontrol_earth.txtleo_sc_prop2.txtsingle_run.control_filessingle_run.aer.datsingle_run.dv.datsingle_run.est_pv.datsingle_run.host_inertial.datsingle_run.residuals.datsingle_run.tar_inertial.datsingle_run.true_pv.datsingle_run.host_ephem.esingle_run.tar_ephem.e
  2.  
My desired output XML (<file>s are sorted by file extension):

Expand|Select|Wrap|Line Numbers
  1. <root name="PlanRepository">
  2.   <directory name="connoraj">
  3.     <directory name="single_run.dat.07-23-2007.10-59-51">
  4.       <file>insidebox.txt</file>
  5.       <file>outsidebox.txt</file>
  6.       <directory name="SAFE_Input">
  7.         <file>single_run.dat</file>
  8.         <file>leapseconds.txt</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.control_files</file> 
  16.         <file>single_run.aer.dat</file>        
  17.         <file>single_run.dv.dat</file>
  18.         <file>single_run.est_pv.dat</file>        
  19.         <file>single_run.host_inertial.dat</file>
  20.         <file>single_run.residuals.dat</file>
  21.         <file>single_run.tar_inertial.dat</file>
  22.         <file>single_run.true_pv.dat</file>
  23.         <file>single_run.host_ephem.e</file>
  24.         <file>single_run.tar_ephem.e</file>        
  25.       </directory>
  26.     </directory>
  27.   </directory>
  28. </root>
  29.  
Can anyone help me out with this problem?

Thanks,
Andrew
Jul 24 '07 #1
1 1863
jkmyoung
2,057 Expert 2GB
For some reason or another, you're not hitting your root template.
Check to make sure that you don't have any xmlns: attribute in your source xml, and that root is spelled with the same capitalization in both your source xml and your xslt.
Jul 24 '07 #2

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

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
14
by: MSR | last post by:
I have a couple of questions. 1. Copy Constructor. class A { private: int a1; double d1; char *ptr;
8
by: luis molina Micasoft | last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make 40 threads of file.copy , 40 copys of files at same time the system is going down and stop responding, this is when i'm...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
3
by: lhr_cool_guy | last post by:
The following code is compiling correctly on Visual Studio .NET 2003 but crashes. The problem is that the copy constructor is not being called when it should be. Am I doing something wrong or is...
10
by: utab | last post by:
Dear all, So passing and returning a class object is the time when to include the definition of the copy constructor into the class definition. But if we don't call by value or return by value, ...
5
by: Martijn van Buul | last post by:
Hi. I'm having a peculiar problem at work. I've been googling for it, but haven't found an authorative answer. In a nutshell (Long story follows), what I'd like to know is: If I have a C++...
13
by: Jeroen | last post by:
Hi all, I'm trying to implement a certain class but I have problems regarding the copy ctor. I'll try to explain this as good as possible and show what I tried thusfar. Because it's not about a...
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
11
by: Dijkstra | last post by:
Hi folks! First, this is the code I'm using to expose the problem: ------------------------------------------------------------------ #include <functional> #include <string> #include...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.