-- 作者:acer2
-- 发布时间:3/24/2005 9:15:00 PM
-- [原创]为客户端分页显示加上动态排序
前几天写了一个客户端分页显示的小程序,可惜的是没有本地排序的功能,我想用Recordset的Sort功能却不能成功,在网上找到了一些排序分页显示的例子,由于自己水平有限,看得很吃力,也终于有点明白,实在太长了。针对我写的客户端分页程序,我也用另一种思路写了个能动态本地分页的例子,供大家批评指正。 这个程序的主要思路是:利用XSL格式文件的排序功能生成一个新数据岛,此数据岛就是我们想得到的已排序数据,然后用RECORDSET方法显示它们。 *************************************************************** xml文件:(略,我只用了三个字段的) XSL文件:(GS.XSL) <?xml version="1.0" encoding="GB2312"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <xsl:apply-templates select="/*"></xsl:apply-templates> </xsl:template> <xsl:template match="/*"> <数据> <xsl:for-each select="./*" order-by="./*[1]"> <test> <字段1><xsl:value-of select="./*[0]" /></字段1> <字段2><xsl:value-of select="./*[1]" /></字段2> <字段3><xsl:value-of select="./*[2]" /></字段3> </test> </xsl:for-each> </数据> </xsl:template> </xsl:stylesheet> ************************************************** 主程序:softpage.htm <html> <head> <script language=vbscript> function zzxmlsj() '以样式表形式重新装载XML数据 sj="<?xml version='1.0' encoding='GB2312'?>"&data.TransformNode(style.DocumentElement) sjd.loadXML sj end function function sort(field) '排序 Style.XMLDocument.selectSingleNode("//@ order-by").value=field zzxmlsj() xyy(1) end function function xyy(ys) '分页显示 sjd.recordset.movefirst if ys<1 then ys=1 '过头 if ys>=sjd.recordset.pageCount then ys=sjd.recordset.pageCount-1 '过尾 sjd.recordset.AbsolutePage=ys xs="<table border=1>" xs=xs&"<thead>" xs=xs&"<td><a href=# onclick=sort('./*[0]')>字段1</a></td>" xs=xs&"<td><a href=# onclick=sort('./*[1]')>字段2</a></td>" xs=xs&"<td><a href=# onclick=sort('-./*[2]')>字段3</a></td>" xs=xs&"</thead>" for i=1 to sjd.recordset.pagesize xs=xs&"<tr>" xs=xs&"<td>"&sjd.recordset(0).value&"</td>" xs=xs&"<td>"&sjd.recordset(1).value&"</td>" xs=xs&"<td>"&sjd.recordset(2).value&"</td>" if sjd.recordset.eof then exit for sjd.recordset.movenext xs=xs&"</tr>" next xs=xs&"</table>" xs=xs&"<input type=button onclick=xyy(1) value='首页'></input>" xs=xs&"<input type=button onclick=xyy("& ys-1 & ") value='上页'></input>" xs=xs&"<input type=button onclick=xyy("& ys+1 & ") value='下页'></input>" xs=xs&"<input type=button onclick=xyy("& sjd.recordset.pageCount-1 & ") value='末页'></input>" xs=xs&"<p>共"&sjd.recordset.Pagecount-1&"页,"&"第"&sjd.recordset.AbsolutePage-1&"页</p>" disp.innerHTML=xs '更新显示 end function </script> </head> <body> <XML ID="data" src="vvv.xml" /> <XML ID="style" src="gs.xsl" /> <xml id="sjd"></xml> <script> zzxmlsj() </script> <div id="disp"></div> <script language="vbscript"> xyy 1 '第一次显示 </script> </body> </html> 在网上的话(ASP)一定要用#include file方法包含数据岛,否则出错。 样式表命名空间必须用<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">,否则order-by无效。
|