View Full Version : Unable to sort table (IE bug?)

Jun 1st, 2003, 10:48 PM
I try to make a generic xml based table sort routing routine.
However, it seems that XSL stylesheet does not in IE 6

To reproduce:

1. create files test.htm, test.xsl and test.htc from data in the end of this message
2. run test.htm in IE 6
3. click in the item column

Observed result:

table is not sorted by item column

Expected result:

Table must be selected by item column


In test.xsl, if line

<xsl:sort select="$sortfield" order="{$sortorder}" />

is changed to

<xsl:sort select="item" order="{$sortorder}" />

The sorting is done.
So this is IE bug!

Any idea how to fix this so that sorting can be done by any column?
Or is it possible to use some other generic method for sorting by any column?

--------- test.htm contains:

<xml id="result" javaDSOCompatible="true">

Click in the item or price to sort
<TABLE DATASRC="#result"
style="BEHAVIOR: url(test.htc)" LANGUAGE="javascript">
<th id="thdr" SortField="item">Item</th>
<th id="thdr" SortField="price">Price</th>

<td><span datafld=item></span></td>
<td><span datafld=price></span></td>
<xml id="xslSorted" src="test.xsl"></xml>

-------- test.xsl contains:

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:param name="sortorder" select="'descending'"/>
<xsl:param name="sortfield" select="'xxx'"/>

<xsl:template match="/">
<xsl:for-each select="result/row" >
<xsl:sort select="$sortfield" order="{$sortorder}" />
<xsl:copy-of select="." />

------------ test.htc contains:

<script language=jscript>

element.attachEvent('onclick', onClick);

function onClick() {
srcElem = window.event.srcElement;
while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE" && srcElem.tagName != "TH") {
srcElem = srcElem.parentElement;
if(srcElem.tagName == "TH") SortJS();

function SortJS()
var nLastCol = element.document.all.thdr.length;
var srcElem = window.event.srcElement;
var strSortOrder = "";
var strSortField = srcElem.SortField;

//Store away the current class name before it gets reset
strCurrClass = srcElem.className;

strSortOrder = "ascending";
SortPickList(strSortField, strSortOrder);


<script language="vbscript">

function SortPickList(strSortField, strSortOrder )

dim objXSL, objXML, objTemplate, objProcessor, strHTML, strDrinkType

Set objXML = CreateObject("Msxml2.FreeThreadedDOMDocument")
Set objXSL = CreateObject("Msxml2.FreeThreadedDOMDocument")

objXML.async = False
objXML.Loadxml result.xml

objXSL.async = False

' Chris recommendation:
objXSL.load "test.xsl"
'objXSL.Loadxml xslSorted.xml

Set objTemplate = CreateObject("MSXML2.XSLTemplate")
Set objTemplate.stylesheet = objXSL
Set objProcessor = objTemplate.createProcessor
objProcessor.input = objXML

objProcessor.AddParameter "sortfield", strSortField
objProcessor.AddParameter "sortorder", strSortOrder

'Store the results of the output into a string.
strXML = objProcessor.output

'Load up an XML DOM object from the recent XML output
objXML.loadxml strXML


'Load our Data Island using our new XML object
result.loadxml objXML.xml
end function

Fly Swatter
Jun 18th, 2003, 10:17 AM
<xsl:sort select="*[name()=$sortfield]" order="{$sortorder}" />