xsl-list
[Top] [All Lists]

RE: XSL-List Digest V5 #135

2004-02-20 15:55:42
Andreas,

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:

<SAVEIdeas>
   <SAVEIdea>
      <SAVE_ID>25</SAVE_ID>
      <date_submitted>01/14/2004</date_submitted>
      <employee>Kathryn Grant</employee>
      <department>OPE</department>
      <idea>Buy faster printers.</idea>
      <status_history>
         <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>
      </status_history>
  </SAVEIdea>
</SAVEIdeas>

<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)'
transform(pass1)
}

function View2()
{
var pass1 = 'date_submitted'
transform(pass1)
}

function View3()
{
var pass1 = 'employee'
transform(pass1)
}

function View4()
{
var pass1 = 'department'
transform(pass1)
}

function View6()
{
var pass1 = 'status_history'
transform(pass1)
}


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
xml.load("/finance/SAVE/fpdb/SAVEIdeas.xml")

// Load the XSL
var xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument")
xsl.async = false
xsl.load("/finance/SAVE/fpdb/SAVEIdeas-sort.xsl")

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

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

processor.transform();  

// Transform
divResults.innerHTML = processor.output;
}
</script>
<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%">

<tr>
<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>
</tr>


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

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

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

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


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

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

</tr>
</xsl:for-each>
</TABLE>    
</xsl:template>

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

</xsl:stylesheet>

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

Kathryn
 
Date: Fri, 20 Feb 2004 21:37:11 +0100
From: "Andreas L. Delmelle" <a_l(_dot_)delmelle(_at_)pandora(_dot_)be>
Subject: RE: [xsl] RE: Troubleshooting a sort

Hi,

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]" />

Cheers,
Andreas

------------------------------

Date: Fri, 20 Feb 2004 20:47:22 GMT
From: David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
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
used.

David


**********************************************************
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



<Prev in Thread] Current Thread [Next in Thread>