转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
用XML创建可排序、分页的数据显示页面         ★★★★

用XML创建可排序、分页的数据显示页面

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1750 更新时间:2009/4/23 11:18:06
.xsl文件的内容:
  
   <?xml version="1.0" encoding="gb2312"?>
   <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]">
   <xsl:sort select="./*[1]" order="ascending"/>
   <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>
   以下是进行输出的Exam.htm文件:
   <HTML>
   <Head>
   <META http=equiv="Content-Type" Content="text/html;charset=gb2312">
   <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

上一页  [1] [2] [3]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台