对xml+xsl实现分页排序
时间:2006-10-14
来源:互联网
帮忙看看这段代码,其中序号是数值型,可是排时不是安数值来排的,怎样才能在排序时把数据类型识别为数字呢,定义了dt:dt="int" 可是排时还是安照字符来排的啊?谢谢!~
<HTML> <Head> <META http=equiv="Content-Type" Content="text/html;charset=gb2312"> <STYLE> body { font-family:宋体; font-size:11pt;} th { font-family:宋体; font-size:11pt; font-weight:bold;} </STYLE> <Script language="vbscript"> Option Explicit Dim intRecordsPerPage '每个页面显示的记录数 intRecordsPerPage = 6 '每个页面显示的记录数,默认设定为6 ' 更新显示页面的函数 Function window_onload() ' 显示设定的记录数 Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]" transform() setPageCount() End Function ' 进行XML-XSLT转换,并显示当前记录的一些信息 Function transform() temp.loadXML (Data.transformNode(SortData.DocumentElement)) DisplayArea.innerHTML = temp.transformNode(Style.DocumentElement) RecordsPerPage.Value = intRecordsPerPage End Function ' 重新转换XML,并显示一个状态信息 Function redisplay(intPage) Dim strDisplay Dim intPageCount Dim intRecordCount ' 保存状态信息 intPageCount = PageCount.innerHTML intRecordCount = RecordCount.innerHTML transform() ' 显示状态信息 PageCount.innerHTML = intPageCount RecordCount.innerHTML = intRecordCount CurrentPage.innerHTML = intPage End Function ' 重新排序和显示 Function Sort(strField) Dim sortField Dim sortOrderAttribute ' 得到排序属性值 Set sortField = SortData.XMLDocument.selectSingleNode("//xsl:sort/@select") Set sortOrderAttribute = SortData.XMLDocument.selectSingleNode("//xsl:sort/@order") ' 改变排序的方式 If sortField.Value = strField Or sortField.Value = "./*[0]" Then If sortOrderAttribute.Value = "descending" Then sortOrderAttribute.Value = "ascending" Else sortOrderAttribute.Value = "descending" End If Else sortField.Value = strField sortOrderAttribute.Value = "ascending" End If Set sortField = Nothing Set sortOrderAttribute = Nothing redisplay (CurrentPage.innerHTML) End Function ' 重新设置每页的记录数 Function setRecordsPerPage() If IsNumeric(RecordsPerPage.Value) Then intRecordsPerPage = CInt(RecordsPerPage.Value) window_onload End If End Function ' 显示页数信息 Function setPageCount() Dim intTotalRecords PageCount.innerHTML = getNumberOfPages(intTotalRecords) RecordCount.innerHTML = intTotalRecords CurrentPage.innerHTML = 1 End Function ' 计算总页数和总记录数 Function getNumberOfPages(intTotalRecords) Dim intPages intTotalRecords = Data.XMLDocument.selectNodes("/*/*").length intPages = intTotalRecords / intRecordsPerPage If InStr(intPages, ".") > 0 Then intPages = CInt(Left(intPages, InStr(intPages, "."))) + 1 End If getNumberOfPages = intPages End Function ' “下一页”的处理 Function nextPage(intPage) Dim strDisplay Dim strDateRange If CInt(CStr(intPage) * intRecordsPerPage) < Data.selectNodes("/*/*").length Then intPage = CInt(intPage) + 1 Style.XMLDocument.selectNodes("//@OnClick")(1).Value = "previousPage(" & intPage & ")" Style.XMLDocument.selectNodes("//@OnClick")(2).Value = "nextPage(" & intPage & ")" Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() <= " & (CStr(intPage) * intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]" redisplay (intPage) End If End Function ' 处理“上一页” Function previousPage(intPage) Dim strDisplay Dim strDateRange If intPage > 1 Then intPage = CInt(intPage) - 1 Style.XMLDocument.selectNodes("//@OnClick")(1).Value = "previousPage(" & intPage & ")" Style.XMLDocument.selectNodes("//@OnClick")(2).Value = "nextPage(" & intPage & ")" Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() <= " & (CStr(intPage) * intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]" redisplay (intPage) End If End Function ' “第一页”的处理 Function FirstPage() Style.XMLDocument.selectNodes("//@OnClick")(1).Value = "previousPage(1)" Style.XMLDocument.selectNodes("//@OnClick")(2).Value = "nextPage(1)" Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]" transform() setPageCount() End Function ' “最末页”的处理 Function LastPage() Dim intTotalPages Dim intTotalRecords intTotalPages = getNumberOfPages(intTotalRecords) nextPage (intTotalPages - 1) End Function </Script> </Head> <body> <h1>对xml+xsl实现分页排序的改进,使支持对所有数据进行排序</h1> <p align="center" style="font-weight:bold;font-size:12pt;color:#0000FF;border-bottom:3px double red;padding-bottom:5px">客户关系表</p> <XML id='Data'> <客户关系表 xmlns:dt="urn:schemas-microsoft-com:datatypes"> <客户><序号 dt:dt="int">1</序号><姓名>dotey</姓名><电子邮件>http://www.webuc.net</电子邮件></客户> <客户><序号 dt:dt="int">2</序号><姓名>孟子E章</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">3</序号><姓名>宝玉</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">4</序号><姓名>http://lucky.myrice.com</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">5</序号><姓名>http://colorweb.go.163.com</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">6</序号><姓名>Frank</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">7</序号><姓名>Greg</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">8</序号><姓名>Harry</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">9</序号><姓名>Ingrid</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">10</序号><姓名>Jeff</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">11</序号><姓名>Kelly</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">12</序号><姓名>Larry</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">13</序号><姓名>Mark</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">14</序号><姓名>Nancy</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">15</序号><姓名>Peter</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">16</序号><姓名>Rachel</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">17</序号><姓名>Seth</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">18</序号><姓名>Tim</姓名><电子邮件>[email protected]</电子邮件></客户> </客户关系表> </XML> <XML id='SortData'> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="客户关系表"> <?xml version="1.0" encoding="GB2312"?> <客户关系表> <xsl:for-each select="客户"> <xsl:sort select="姓名" order="ascending"/> <客户> <序号><xsl:value-of select="序号" /></序号> <姓名><xsl:value-of select="姓名" /></姓名> <电子邮件><xsl:value-of select="电子邮件" /></电子邮件> </客户> </xsl:for-each> </客户关系表> </xsl:template> </xsl:stylesheet> </XML> <XML id='Style'> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://lucky.myrice.com" version="1.0"> <msxsl:script language="VBScript" implements-prefix="user"> <![CDATA[ Function getName(node) getName = node.Item(0).nodeName End Function ]]> </msxsl:script> <xsl:template match="/"> <xsl:apply-templates select="/*"/> </xsl:template> <xsl:template match="/*"> <table width="100%" border="0" style="font-size:9pt"> <tr> <td align="left"><b>第 <span id="CurrentPage"></span> 页 总 <span id="PageCount"></span> 页 共有 <span id="RecordCount"></span> 条记录</b></td> <td align="right"><b>每页记录数:<input onBlur="setRecordsPerPage()" id="RecordsPerPage" style="vertical-align:middle;height:15pt;width:30px"/></b></td> <td align="right"> <span id="Paging"> <input type="button" OnClick="FirstPage()" value="第一页"/> <input type="button" OnClick="previousPage(1)" value="上一页"/> <input type="button" OnClick="nextPage(1)" value="下一页"/> <input type="button" OnClick="LastPage()" value="最末页"/> </span> </td> </tr> </table> <Table WIDTH="100%" BORDER="0" cellpadding="0" cellspacing="1" style="font-size:11pt" bgcolor="#0099ff"> <tr bgcolor="#FF6600" style="cursor: hand;padding:5px"> <xsl:for-each select="./*[1]/*"> <td align="center"> <xsl:attribute name="onclick"> Sort('<xsl:value-of select="user:getName(.)"/>') </xsl:attribute> <font color="#EEEEEE"><b><u><xsl:value-of select="user:getName(.)"/></u></b></font> </td> </xsl:for-each> </tr> <xsl:for-each select="./*[position() < 6 and position() > 0]"> <tr bgcolor="#FFCCFF"> <xsl:for-each select="./*"> <td> <xsl:value-of select="."/></td> </xsl:for-each> </tr> </xsl:for-each> </Table> </xsl:template> </xsl:stylesheet> </XML> <XML id="temp"/> <div id="DisplayArea"></div> <table border="0" width="100%" style="font-size:11pt;"> <tr> <td align="right">【<a href="http://www.webuc.net/dotey">宝玉@webuc.net</a>】修改自:【<a href="http://lucky.myrice.com">孟宪会之精彩世界</a>】</td> </tr> </table> </body> </HTML>
提示:您可以先修改部分代码再运行
[[i] 本帖最后由 鱼儿游 于 2006-10-14 11:46 编辑 [/i]]
<HTML> <Head> <META http=equiv="Content-Type" Content="text/html;charset=gb2312"> <STYLE> body { font-family:宋体; font-size:11pt;} th { font-family:宋体; font-size:11pt; font-weight:bold;} </STYLE> <Script language="vbscript"> Option Explicit Dim intRecordsPerPage '每个页面显示的记录数 intRecordsPerPage = 6 '每个页面显示的记录数,默认设定为6 ' 更新显示页面的函数 Function window_onload() ' 显示设定的记录数 Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]" transform() setPageCount() End Function ' 进行XML-XSLT转换,并显示当前记录的一些信息 Function transform() temp.loadXML (Data.transformNode(SortData.DocumentElement)) DisplayArea.innerHTML = temp.transformNode(Style.DocumentElement) RecordsPerPage.Value = intRecordsPerPage End Function ' 重新转换XML,并显示一个状态信息 Function redisplay(intPage) Dim strDisplay Dim intPageCount Dim intRecordCount ' 保存状态信息 intPageCount = PageCount.innerHTML intRecordCount = RecordCount.innerHTML transform() ' 显示状态信息 PageCount.innerHTML = intPageCount RecordCount.innerHTML = intRecordCount CurrentPage.innerHTML = intPage End Function ' 重新排序和显示 Function Sort(strField) Dim sortField Dim sortOrderAttribute ' 得到排序属性值 Set sortField = SortData.XMLDocument.selectSingleNode("//xsl:sort/@select") Set sortOrderAttribute = SortData.XMLDocument.selectSingleNode("//xsl:sort/@order") ' 改变排序的方式 If sortField.Value = strField Or sortField.Value = "./*[0]" Then If sortOrderAttribute.Value = "descending" Then sortOrderAttribute.Value = "ascending" Else sortOrderAttribute.Value = "descending" End If Else sortField.Value = strField sortOrderAttribute.Value = "ascending" End If Set sortField = Nothing Set sortOrderAttribute = Nothing redisplay (CurrentPage.innerHTML) End Function ' 重新设置每页的记录数 Function setRecordsPerPage() If IsNumeric(RecordsPerPage.Value) Then intRecordsPerPage = CInt(RecordsPerPage.Value) window_onload End If End Function ' 显示页数信息 Function setPageCount() Dim intTotalRecords PageCount.innerHTML = getNumberOfPages(intTotalRecords) RecordCount.innerHTML = intTotalRecords CurrentPage.innerHTML = 1 End Function ' 计算总页数和总记录数 Function getNumberOfPages(intTotalRecords) Dim intPages intTotalRecords = Data.XMLDocument.selectNodes("/*/*").length intPages = intTotalRecords / intRecordsPerPage If InStr(intPages, ".") > 0 Then intPages = CInt(Left(intPages, InStr(intPages, "."))) + 1 End If getNumberOfPages = intPages End Function ' “下一页”的处理 Function nextPage(intPage) Dim strDisplay Dim strDateRange If CInt(CStr(intPage) * intRecordsPerPage) < Data.selectNodes("/*/*").length Then intPage = CInt(intPage) + 1 Style.XMLDocument.selectNodes("//@OnClick")(1).Value = "previousPage(" & intPage & ")" Style.XMLDocument.selectNodes("//@OnClick")(2).Value = "nextPage(" & intPage & ")" Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() <= " & (CStr(intPage) * intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]" redisplay (intPage) End If End Function ' 处理“上一页” Function previousPage(intPage) Dim strDisplay Dim strDateRange If intPage > 1 Then intPage = CInt(intPage) - 1 Style.XMLDocument.selectNodes("//@OnClick")(1).Value = "previousPage(" & intPage & ")" Style.XMLDocument.selectNodes("//@OnClick")(2).Value = "nextPage(" & intPage & ")" Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() <= " & (CStr(intPage) * intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]" redisplay (intPage) End If End Function ' “第一页”的处理 Function FirstPage() Style.XMLDocument.selectNodes("//@OnClick")(1).Value = "previousPage(1)" Style.XMLDocument.selectNodes("//@OnClick")(2).Value = "nextPage(1)" Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]" transform() setPageCount() End Function ' “最末页”的处理 Function LastPage() Dim intTotalPages Dim intTotalRecords intTotalPages = getNumberOfPages(intTotalRecords) nextPage (intTotalPages - 1) End Function </Script> </Head> <body> <h1>对xml+xsl实现分页排序的改进,使支持对所有数据进行排序</h1> <p align="center" style="font-weight:bold;font-size:12pt;color:#0000FF;border-bottom:3px double red;padding-bottom:5px">客户关系表</p> <XML id='Data'> <客户关系表 xmlns:dt="urn:schemas-microsoft-com:datatypes"> <客户><序号 dt:dt="int">1</序号><姓名>dotey</姓名><电子邮件>http://www.webuc.net</电子邮件></客户> <客户><序号 dt:dt="int">2</序号><姓名>孟子E章</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">3</序号><姓名>宝玉</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">4</序号><姓名>http://lucky.myrice.com</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">5</序号><姓名>http://colorweb.go.163.com</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">6</序号><姓名>Frank</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">7</序号><姓名>Greg</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">8</序号><姓名>Harry</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">9</序号><姓名>Ingrid</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">10</序号><姓名>Jeff</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">11</序号><姓名>Kelly</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">12</序号><姓名>Larry</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">13</序号><姓名>Mark</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">14</序号><姓名>Nancy</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">15</序号><姓名>Peter</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">16</序号><姓名>Rachel</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">17</序号><姓名>Seth</姓名><电子邮件>[email protected]</电子邮件></客户> <客户><序号 dt:dt="int">18</序号><姓名>Tim</姓名><电子邮件>[email protected]</电子邮件></客户> </客户关系表> </XML> <XML id='SortData'> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="客户关系表"> <?xml version="1.0" encoding="GB2312"?> <客户关系表> <xsl:for-each select="客户"> <xsl:sort select="姓名" order="ascending"/> <客户> <序号><xsl:value-of select="序号" /></序号> <姓名><xsl:value-of select="姓名" /></姓名> <电子邮件><xsl:value-of select="电子邮件" /></电子邮件> </客户> </xsl:for-each> </客户关系表> </xsl:template> </xsl:stylesheet> </XML> <XML id='Style'> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://lucky.myrice.com" version="1.0"> <msxsl:script language="VBScript" implements-prefix="user"> <![CDATA[ Function getName(node) getName = node.Item(0).nodeName End Function ]]> </msxsl:script> <xsl:template match="/"> <xsl:apply-templates select="/*"/> </xsl:template> <xsl:template match="/*"> <table width="100%" border="0" style="font-size:9pt"> <tr> <td align="left"><b>第 <span id="CurrentPage"></span> 页 总 <span id="PageCount"></span> 页 共有 <span id="RecordCount"></span> 条记录</b></td> <td align="right"><b>每页记录数:<input onBlur="setRecordsPerPage()" id="RecordsPerPage" style="vertical-align:middle;height:15pt;width:30px"/></b></td> <td align="right"> <span id="Paging"> <input type="button" OnClick="FirstPage()" value="第一页"/> <input type="button" OnClick="previousPage(1)" value="上一页"/> <input type="button" OnClick="nextPage(1)" value="下一页"/> <input type="button" OnClick="LastPage()" value="最末页"/> </span> </td> </tr> </table> <Table WIDTH="100%" BORDER="0" cellpadding="0" cellspacing="1" style="font-size:11pt" bgcolor="#0099ff"> <tr bgcolor="#FF6600" style="cursor: hand;padding:5px"> <xsl:for-each select="./*[1]/*"> <td align="center"> <xsl:attribute name="onclick"> Sort('<xsl:value-of select="user:getName(.)"/>') </xsl:attribute> <font color="#EEEEEE"><b><u><xsl:value-of select="user:getName(.)"/></u></b></font> </td> </xsl:for-each> </tr> <xsl:for-each select="./*[position() < 6 and position() > 0]"> <tr bgcolor="#FFCCFF"> <xsl:for-each select="./*"> <td> <xsl:value-of select="."/></td> </xsl:for-each> </tr> </xsl:for-each> </Table> </xsl:template> </xsl:stylesheet> </XML> <XML id="temp"/> <div id="DisplayArea"></div> <table border="0" width="100%" style="font-size:11pt;"> <tr> <td align="right">【<a href="http://www.webuc.net/dotey">宝玉@webuc.net</a>】修改自:【<a href="http://lucky.myrice.com">孟宪会之精彩世界</a>】</td> </tr> </table> </body> </HTML>
提示:您可以先修改部分代码再运行
[[i] 本帖最后由 鱼儿游 于 2006-10-14 11:46 编辑 [/i]]
作者: 鱼儿游 发布时间: 2006-10-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28