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:
My XSL File:
My resulting output:
My desired output XML (<file>s are sorted by file extension):
Can anyone help me out with this problem?
Thanks,
Andrew
My Sample XML:
Code:
<root name="PlanRepository">
<directory name="connoraj">
<directory name="single_run.dat.07-23-2007.10-59-51">
<file>insidebox.txt</file>
<file>outsidebox.txt</file>
<directory name="SAFE_Input">
<file>leapseconds.txt</file>
<file>single_run.dat</file>
<directory name="LeoInputs">
<file>control_earth.txt</file>
<file>leo_sc_prop2.txt</file>
</directory>
</directory>
<directory name="SAFE_Output">
<file>single_run.aer.dat</file>
<file>single_run.control_files</file>
<file>single_run.dv.dat</file>
<file>single_run.est_pv.dat</file>
<file>single_run.host_ephem.e</file>
<file>single_run.host_inertial.dat</file>
<file>single_run.residuals.dat</file>
<file>single_run.tar_ephem.e</file>
<file>single_run.tar_inertial.dat</file>
<file>single_run.true_pv.dat</file>
</directory>
</directory>
</directory>
</root>
Code:
<xsl:template match="root">
<xsl:copy>
<xsl:attribute name="name">PlanRepository</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="directory">
<xsl:copy>
<xsl:copy-of select="@name"/>
<xsl:choose>
<xsl:when test="@name = 'SAFE_Output'">
<xsl:for-each select="file">
<xsl:sort select="substring-after(substring-after(.,'.'),'.')" />
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="file">
<xsl:sort select="substring-after(.,'.')" />
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="directory"/>
</xsl:copy>
</xsl:template>
Code:
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
Code:
<root name="PlanRepository">
<directory name="connoraj">
<directory name="single_run.dat.07-23-2007.10-59-51">
<file>insidebox.txt</file>
<file>outsidebox.txt</file>
<directory name="SAFE_Input">
<file>single_run.dat</file>
<file>leapseconds.txt</file>
<directory name="LeoInputs">
<file>control_earth.txt</file>
<file>leo_sc_prop2.txt</file>
</directory>
</directory>
<directory name="SAFE_Output">
<file>single_run.control_files</file>
<file>single_run.aer.dat</file>
<file>single_run.dv.dat</file>
<file>single_run.est_pv.dat</file>
<file>single_run.host_inertial.dat</file>
<file>single_run.residuals.dat</file>
<file>single_run.tar_inertial.dat</file>
<file>single_run.true_pv.dat</file>
<file>single_run.host_ephem.e</file>
<file>single_run.tar_ephem.e</file>
</directory>
</directory>
</directory>
</root>
Thanks,
Andrew
Comment