使用XML、XSLT和XPath创建可排序、分页、重用的数据显示页
请选择段落导航
1.使用XML、XSLT和XPath创建可排序、分页、重用的数据显示页(1)
2.使用XML、XSLT和XPath创建可排序、分页、重用的数据显示页(2)
3.使用XML、XSLT和XPath创建可排序、分页、重用的数据显示页(3)
4.使用XML、XSLT和XPath创建可排序、分页、重用的数据显示页(4)
使用XML、XSLT和XPath创建可排序、分页、重用的数据显示页(3)
<STYLE>
body { font-family:宋体; font-size:9pt;}
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() DisplayArea.innerHTML = Data.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 = Style.XMLDocument.selectSingleNode("//xsl:sort/@select") Set sortOrderAttribute = Style.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> <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">01</序号><姓名>Mi</姓名><电子邮件>water@21cn.com</电子邮件></客户>来源:十度教育 作者: 关键字:数据显示页 发表日期:2006-9-5 14:41:51
网页显示有限 阅读全文请下载本文完整版WORD文档
上一篇:利用oleDB对象,将数据库中全部表转换成XML文件 下一篇:SQL Server和XML的集成
共4页 9 7 [1 ] [2 ] [3 ] [4 ] 8 : >
2009-1-8 7:26:20