Re: [xsl] xsl:sort now working under unix

Subject: Re: [xsl] xsl:sort now working under unix
From: Sylvia Murphy <murphys@xxxxxxxx>
Date: Wed, 22 Dec 2004 15:54:12 -0700
Hi Anton,

that did help. this is of course the streamlined version to see if I could get sort working period. My more complicated real issue still does not work
so there is probably a slightly different syntactical issue.

In my real code, I am combining multiple xml files using:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xml" href="./status_style.xsl"?>
<title>Summary of CCSM Production Runs</title>
<case filename="./b30.043.xml"/>
<case filename="./b30.999.xml"/>
<case filename="./b30.100.02.xml"/>

the above is what I load in the browser.

an example of one of these xml files is: <case> <name>b30.999</name>

<start_info>hybrid b30.999 year 100</start_info>


<proj_end_year> ?? </proj_end_year>


<description>1870 Control</description>



<history> xlink to WREQ </history>

 <!--running, completed, halted, or aborted-->


here is the stylesheet. I will need to be able to sort all these cases by various parameters in the xml files:

<?xml version= "1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="";>

<xsl:template match="/">
<title><xsl:value-of select="/runs/title"/></title>
<link rel="stylesheet" type="text/css" href="/cseg/doc.css"></link>
<h1> CCSM Production Run Status</h1>
<table cellpadding="4" cellspacing="4" border="1">
<tr bgcolor = "#c6EFF7">
<td>Start Info</td>
<td>Start Year</td>
<td>End Year</td>
<xsl:for-each select="/runs/case">
<!--ascending or descending--> <xsl:apply-templates select="document(@filename)/case">
<xsl:sort select="/case/status" data-type = "text" order="descending"/>


<!-- this portion is actually what occurs in the middle of the table--> <xsl:template match="case"> <tr> <td><xsl:value-of select="name"/></td> <xsl:if test="status = 'aborted'"> <td bgcolor="red"><xsl:value-of select="status"/></td> </xsl:if> <xsl:if test="status = 'halted'"> <td bgcolor="#FFCE9C"><xsl:value-of select="status"/></td> </xsl:if> <xsl:if test="status = 'completed'"> <td bgcolor="#EFF8AD"><xsl:value-of select="status"/></td> </xsl:if> <xsl:if test="status = 'running'"> <td bgcolor="#CE84C6"><xsl:value-of select="status"/></td> </xsl:if> <td><xsl:value-of select="start_info"/></td> <td><xsl:value-of select="start_year"/></td> <td><xsl:value-of select="proj_end_year"/></td> <td><xsl:value-of select="res"/></td> <td><xsl:value-of select="tag"/></td> <td><xsl:value-of select="queue"/></td> <td><xsl:value-of select="description"/></td> <td><xsl:value-of select="history"/></td> </tr>



Anton Triest wrote:

Hi Sylvia,

   <xsl:for-each select="addressbook">
<!--descending or ascending (default) -->
     <xsl:sort select="age" data-type="number" order="descending"/>

xsl:sort works on the for-each that precedes it, not on the apply-templates that follows it. So this code will sort the addressbook elements, instead of the address elements. That's why they appear in input-document order. Try replacing the above snippet with something like:

<xsl:for-each select="addressbook">
  <xsl:apply-templates select="address">
      <xsl:sort select="age" data-type="number" order="descending"/>


Current Thread