分享
 
 
 

对数据岛数据实现动态排序二法

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

现在数据岛被越来越广泛的应用;其中必然会涉及到的就是动态排序了;下面列出两种实现方法:

1、为<xsl:param>标签设定参数实现动态排序(推荐)

<html>

<body>

<table DATASRC="#catalogs" border=1>

<thead>

<tr>

<td onclick="sort('TITLE','descending');">TITLE</td>

<td>ARTIST</td>

<td onclick="sort('COUNTRY','ascending');">COUNTRY</td>

<td>COMPANY</td>

<td>PRICE</td>

<td>YEAR</td>

</tr>

</thead>

<tbody>

<tr>

<td ><div DATAFLD="TITLE"></div></td>

<td ><div DATAFLD="ARTIST"></div></td>

<td ><div DATAFLD="COUNTRY"></div></td>

<td ><div DATAFLD="COMPANY"></div></td>

<td ><div DATAFLD="PRICE"></div></td>

<td ><div DATAFLD="YEAR"></div></td>

</tr>

</tbody>

</table>

<xml id="catalogs">

<CATALOG>

<CD>

<TITLE>Empire Burlesque</TITLE>

Bob Dylan

<COUNTRY>USA</COUNTRY>

<COMPANY>Columbia</COMPANY>

<PRICE>10.90</PRICE>

<YEAR>1985</YEAR>

</CD>

<CD>

<TITLE>Burlesque</TITLE>

Dylan

<COUNTRY>UA</COUNTRY>

<COMPANY>umbia</COMPANY>

<PRICE>1.90</PRICE>

<YEAR>1987</YEAR>

</CD>

<CD>

<TITLE>Empire</TITLE>

Bob

<COUNTRY>US</COUNTRY>

<COMPANY>bia</COMPANY>

<PRICE>12.90</PRICE>

<YEAR>1995</YEAR>

</CD>

</CATALOG>

</xml>

<xml id="xstyle">

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

<CATALOG>

<xsl:for-each select="CATALOG/CD">

<xsl:sort select="*[name()=$sortfield]" order="{$sortorder}" />

<CD>

<TITLE><xsl:value-of select="TITLE"/></TITLE>

<xsl:value-of select="ARTIST"/>

<COUNTRY><xsl:value-of select="COUNTRY"/></COUNTRY>

<COMPANY><xsl:value-of select="COMPANY"/></COMPANY>

<PRICE><xsl:value-of select="PRICE"/></PRICE>

<YEAR><xsl:value-of select="YEAR"/></YEAR>

</CD>

</xsl:for-each>

</CATALOG>

</xsl:template>

</xsl:stylesheet>

</xml>

<script language="vbscript">

function sort(strSortField, strSortOrder)

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

Set objXML = CreateObject("Msxml2.FreeThreadedDOMDocument")

Set objXSL = CreateObject("Msxml2.FreeThreadedDOMDocument")

'Load the XML document

objXML.async = False

objXML.Loadxml catalogs.xml

'Load the XSL document

objXSL.async = False

objXSL.Loadxml xstyle.xml

'Create an instance of our XSL Template object

Set objTemplate = CreateObject("MSXML2.XSLTemplate")

'Create an instance of our stylesheet object using our recently loaded XSLT document

Set objTemplate.stylesheet = objXSL

'Create an instance of our Processor object

Set objProcessor = objTemplate.createProcessor

'Define the input object for our object equal to our recently loaded XML document

objProcessor.input = objXML

'Now, finally we can add any parameters that we require to our Template processor

objProcessor.AddParameter "sortfield", strSortField

objProcessor.AddParameter "sortorder", strSortOrder

'Last but not least we do our transformation

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

'Select only the "employees" elements from our document object

objXML.selectNodes("//CATALOG")

'Load our Data Island using our new XML object

catalogs.loadxml objXML.xml

end function

</script>

<script language="javascript">

function sort2(xmlObj, xslObj, sortByColName)

{

var xmlData=eval("document.all."+xmlObj).XMLDocument;

var xslData=eval("document.all."+xslObj).XMLDocument;

var nodes=xslData.documentElement.selectSingleNode("xsl:for-each");

nodes.selectSingleNode("@order-by").value=sortByColName;

xmlData.documentElement.transformNodeToObject(xslData.documentElement,xmlData);

}

</script>

</body>

</html>

2、直接通过DOM实现,灵活性欠缺:

<html>

<body>

<table DATASRC="#catalogs" border=1>

<thead>

<tr>

<td onclick="sort('catalogs','xstyle','TITLE');">TITLE</td>

<td>ARTIST</td>

<td>COUNTRY</td>

<td>COMPANY</td>

<td>PRICE</td>

<td>YEAR</td>

</tr>

</thead>

<tbody>

<tr>

<td ><div DATAFLD="TITLE"></div></td>

<td ><div DATAFLD="ARTIST"></div></td>

<td ><div DATAFLD="COUNTRY"></div></td>

<td ><div DATAFLD="COMPANY"></div></td>

<td ><div DATAFLD="PRICE"></div></td>

<td ><div DATAFLD="YEAR"></div></td>

</tr>

</tbody>

</table>

<xml id='catalogs'>

<CATALOG>

<CD>

<TITLE>Empire Burlesque</TITLE>

Bob Dylan

<COUNTRY>USA</COUNTRY>

<COMPANY>Columbia</COMPANY>

<PRICE>10.90</PRICE>

<YEAR>1985</YEAR>

</CD>

<CD>

<TITLE>Burlesque</TITLE>

Dylan

<COUNTRY>UA</COUNTRY>

<COMPANY>umbia</COMPANY>

<PRICE>1.90</PRICE>

<YEAR>1987</YEAR>

</CD>

<CD>

<TITLE>Empire</TITLE>

Bob

<COUNTRY>US</COUNTRY>

<COMPANY>bia</COMPANY>

<PRICE>12.90</PRICE>

<YEAR>1995</YEAR>

</CD>

</CATALOG>

</xml>

<xml id="xstyle">

<CATALOG>

<xsl:for-each select="CD" order-by="+TITLE" xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<CD>

<TITLE><xsl:value-of select="TITLE"/></TITLE>

<xsl:value-of select="ARTIST"/>

<COUNTRY><xsl:value-of select="COUNTRY"/></COUNTRY>

<COMPANY><xsl:value-of select="COMPANY"/></COMPANY>

<PRICE><xsl:value-of select="PRICE"/></PRICE>

<YEAR><xsl:value-of select="YEAR"/></YEAR>

</CD>

</xsl:for-each>

</CATALOG>

</xml>

<script language="javascript">

function sort(xmlObj, xslObj, sortByColName)

{

var xmlData=eval("document.all."+xmlObj).XMLDocument;

var xslData=eval("document.all."+xslObj).XMLDocument;

var nodes=xslData.documentElement.selectSingleNode("xsl:for-each");

nodes.selectSingleNode("@order-by").value=sortByColName;

xmlData.documentElement.transformNodeToObject(xslData.documentElement,xmlData);

}

</script>

</body>

</html>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有