手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Xml编程>列表

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

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!




以下是完整的Style.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

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!