[xsl] RE: XSL-List Digest V5 #135

Subject: [xsl] RE: XSL-List Digest V5 #135
From: "Grant, Kathryn --- Sr. Technical Writer --- WGO" <Kathryn.Grant@xxxxxxxxxxxxxxxxx>
Date: Fri, 20 Feb 2004 14:55:42 -0800

The new code didn't work (but thanks!) And David, as you rightly pointed out, I didn't include the root element in my XML snippet, and I was probably too brief in my explanation (trying not to make my emails too long). So with many thanks for your patience, here goes again:

Here's some representative XML:

      <employee>Kathryn Grant</employee>
      <idea>Buy faster printers.</idea>
         <status timestamp="1/20/04, 4:33:13 PM" userID="GRANT01">Submitted for supervisor review</status>
         <status timestamp="1/25/04, 9:21:45 AM" userID="GRANT01">Submitted for CFO review</status>
         <status timestamp="1/29/04, 6:12:22 PM" userID="GRANT01">Approved</status>

<SAVEIdeas> is the root element.

My web page contains a JavaScript which transforms XML with XSL to create a sortable table of SAVE ideas (sorts are performed by clicking on column headings). Column headings are SAVE ID, Date Submitted, Employee, Department, and Status (corresponding to the XML tags above). There is only one occurrence of each element per XML record, EXCEPT for the status element, which may occur multiple times. The table displays the LAST status element of each record. But the sort on that column isn't working.

Following are the js functions which are hyperlinked to each column heading. They initialize a js variable with the tag name corresponding to the column:

function View1()
var pass1 = 'number(SAVE_ID)'

function View2()
var pass1 = 'date_submitted'

function View3()
var pass1 = 'employee'

function View4()
var pass1 = 'department'

function View6()
var pass1 = 'status_history'

The variable is then passed to the XSL file as a parameter during the following transformation:

function transform(x)
// Load XML
var xml = new ActiveXObject("MSXML2.DOMDocument")
xml.async = false

// Load the XSL
var xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument")
xsl.async = false

template = new ActiveXObject("Msxml2.XSLTemplate");
template.stylesheet = xsl;

processor = template.createProcessor();
processor.input = xml;
processor.addParameter("param1", x);


// Transform
divResults.innerHTML = processor.output;
<DIV ID="divResults" align="center">&nbsp;</div>

Below is the XSL file. The clickable column headings sort each column correctly EXCEPT the status column. How can I get the status column to sort correctly? I'm sure it's not working because the status element is one level down from the other elements which are being sorted. 

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

<xsl:param name="param1"/>

<xsl:output method="html"/>
<xsl:template match="/">

<TABLE border="0" width="100%">

<th width="7%"><a href="javascript:View1()"><b>SAVE ID</b></a></th>
<th width="14%"><a href="javascript:View2()"><b>Date Submitted</b></a></th>
<th width="17%"><a href="javascript:View3()"><b>Submitted by</b></a><br/><a href="javascript:View4()"><b>(Department)</b></a></th>
<th width="29%" valign="bottom"><b>Idea</b></th>
<th width="33%" valign="bottom"><a href="javascript:View6()"><b>Status</b></a></th>

<xsl:for-each select="//SAVEIdeas/SAVEIdea">
<xsl:sort select="(*|*/*)[name()=$param1][last()]"/>

   <td style="font-size:8pt" valign="top">
     <a href='javascript:loadnew2({SAVE_ID})'><xsl:value-of select="SAVE_ID"/></a>

  <td style="font-size:8pt" valign="top">
    <xsl:value-of select="date_submitted"/>

  <td style="font-size:8pt" valign="top">
    <xsl:value-of select="employee"/> (<xsl:value-of select="department"/>)

  <td style="font-size:8pt" valign="top">
        <xsl:value-of select="idea"/>

  <td style="font-size:8pt" valign="top">
    <xsl:apply-templates select="status_history"/>


<xsl:template match="status_history">
  <xsl:value-of select="status[last()]"/>


Hopefully that is enough information to solve this mystery. Thanks for your help!

Date: Fri, 20 Feb 2004 21:37:11 +0100
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Subject: RE: [xsl] RE: Troubleshooting a sort


IIC the sort should be performed in the correct way now.. :/

However.. very remote guess
> <xsl:for-each select="//SAVEIdeas/SAVEIdea">
> <xsl:sort select="(*|*/*)[name()=$param1][last()]"/>

try making that:
  <xsl:sort select=(*|*/*[last()])[name()=$param1]" />



Date: Fri, 20 Feb 2004 20:47:22 GMT
From: David Carlisle <davidc@xxxxxxxxx>
Subject: Re: [xsl] RE: Troubleshooting a sort

are you sure the problem isn't in parts you havent shown (eg the setting
of the param, the definition of View6 etc) You posted a lot of code but
its not much help as it can't be run on the posted input doc (which had
no SAVEIdeas element) and has no definition of the javascript functions


This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread