Unable to sort table (IE bug?)
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
Note:
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">
<result>
<row><item>pine</item><price>4</price></row>
<row><item>orange</item><price>1</price></row>
<row><item>apple</item><price>3</price></row>
</result></xml>
Click in the item or price to sort
<TABLE DATASRC="#result"
style="BEHAVIOR: url(test.htc)" LANGUAGE="javascript">
<thead>
<th id="thdr" SortField="item">Item</th>
<th id="thdr" SortField="price">Price</th>
</thead>
<tr>
<td><span datafld=item></span></td>
<td><span datafld=price></span></td>
</tr>
</TABLE>
<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="/">
<result>
<xsl:for-each select="result/row" >
<xsl:sort select="$sortfield" order="{$sortorder}" />
<xsl:copy-of select="." />
</xsl:for-each>
</result>
</xsl:template>
</xsl:stylesheet>
------------ 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>
<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
objProcessor.Transform
'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
objXML.selectNodes("//result")
'Load our Data Island using our new XML object
result.loadxml objXML.xml
end function
</script>
Last edited by Alex Vincent; 06-04-2003 at 06:05 PM..
|