<?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>每頁記錄數(shù):<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>
以下是進(jìn)行輸出的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 '每個頁面顯示的記錄數(shù)
intRecordsPerPage = 6 '每個頁面顯示的記錄數(shù),默認(rèn)設(shè)定為6
' 更新顯示頁面的函數(shù)
Function window_onload()
' 顯示設(shè)定的記錄數(shù)
Style.XMLDocument.selectNodes("http://xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]"
transform()
setPageCount()
End Function
' 進(jìn)行XML-XSLT轉(zhuǎn)換,并顯示當(dāng)前記錄的一些信息
Function transform()
DisplayArea.innerHTML = Data.transformNode(Style.DocumentElement)
RecordsPerPage.Value = intRecordsPerPage
End Function
' 重新轉(zhuǎn)換XML,并顯示一個狀態(tài)信息
Function redisplay(intPage)
Dim strDisplay
Dim intPageCount
Dim intRecordCount
' 保存狀態(tài)信息
intPageCount = PageCount.innerHTML
intRecordCount = RecordCount.innerHTML
transform()
' 顯示狀態(tài)信息
PageCount.innerHTML = intPageCount
RecordCount.innerHTML = intRecordCount
CurrentPage.innerHTML = intPage
End Function
' 重新排序和顯示
Function Sort(strField)
Dim sortField
Dim sortOrderAttribute
' 得到排序?qū)傩灾?BR>
Set sortField = Style.XMLDocument.selectSingleNode("http://xsl:sort/@select")
Set sortOrderAttribute = Style.XMLDocument.selectSingleNode("http://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
' 重新設(shè)置每頁的記錄數(shù)
Function setRecordsPerPage()
If IsNumeric(RecordsPerPage.Value) Then
intRecordsPerPage = CInt(RecordsPerPage.Value)
window_onload
End If
End Function
' 顯示頁數(shù)信息
Function setPageCount()
Dim intTotalRecords
PageCount.innerHTML = getNumberOfPages(intTotalRecords)
RecordCount.innerHTML = intTotalRecords
CurrentPage.innerHTML = 1
End Function
' 計算總頁數(shù)和總記錄數(shù)
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("http://@OnClick")(1).Value = "previousPage(" & intPage & ")"
Style.XMLDocument.selectNodes("http://@OnClick")(2).Value = "nextPage(" & intPage & ")"
Style.XMLDocument.selectNodes("http://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("http://@OnClick")(1).Value = "previousPage(" & intPage & ")"
Style.XMLDocument.selectNodes("http://@OnClick")(2).Value = "nextPage(" & intPage & ")"
Style.XMLDocument.selectNodes("http://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("http://@OnClick")(1).Value = "previousPage(1)"
Style.XMLDocument.selectNodes("http://@OnClick")(2).Value = "nextPage(1)"
Style.XMLDocument.selectNodes("http://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">客戶關(guān)系表</p>
<XML id='Data'>
<客戶關(guān)系表 xmlns:dt="urn:schemas-microsoft-com:datatypes">
<客戶><序號 dt:dt="int">01</序號><姓名>Mi</姓名><電子郵件>water@21cn.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">02</序號><姓名>uyi</姓名><電子郵件>Lily@sina.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">03</序號><姓名>uiyu</姓名><電子郵件>John@21cn.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">04</序號><姓名>Doug</姓名><電子郵件>Karry@163.net</電子郵件></客戶>
<客戶><序號 dt:dt="int">05</序號><姓名>Ellen</姓名><電子郵件>vivki@sina.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">06</序號><姓名>Frank</姓名><電子郵件>net_lover@mengxianhui.com.cn</電子郵件></客戶>
<客戶><序號 dt:dt="int">07</序號><姓名>Greg</姓名><電子郵件>meng@mengxianhui.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">08</序號><姓名>Harry</姓名><電子郵件>sunny@xianhui.net</電子郵件></客戶>
<客戶><序號 dt:dt="int">09</序號><姓名>Ingrid</姓名><電子郵件>cathy@hotmail.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">10</序號><姓名>Jeff</姓名><電子郵件>your@mxh.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">11</序號><姓名>Kelly</姓名><電子郵件>Iloveyou@mengxianhui.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">12</序號><姓名>Larry</姓名><電子郵件>smilling@mengxianhui.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">13</序號><姓名>Mark</姓名><電子郵件>money@21cn.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">14</序號><姓名>Nancy</姓名><電子郵件>www@yahoo.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">15</序號><姓名>Peter</姓名><電子郵件>dotnet@aol.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">16</序號><姓名>Rachel</姓名><電子郵件>billgates@microsoft.com</電子郵件></客戶>
<客戶><序號 dt:dt="int">17</序號><姓名>Seth</姓名><電子郵件>flying@yous.net</電子郵件></客戶>
<客戶><序號 dt:dt="int">18</序號><姓名>Tim</姓名><電子郵件>agooyboy@lovegirl.com</電子郵件></客戶>
</客戶關(guān)系表>
</XML>
<XML id='Style' src='Style.xsl'></XML>
<div id="DisplayArea"></div>
<table border="0" width="100%" style="font-size:11pt;">
<tr>
<td align="right">資料來源:【<a >孟憲會之精彩世界</a>】</td>
</tr>
</table>
</body>
</HTML>
把上面的內(nèi)容拷貝到本地計算機(jī)上,分別保存為相應(yīng)的文件,在IE5+和XML3.0+的環(huán)境下即可看到效果!