MSN 历史纪录分页显示(XML + XSL + Javascript)
MSN自带的XSL无分业功能,写一个简单的分页XSL:
将此文件替换MSN原有的XSL文件:MessageLog.xsl 即可
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="PageCount">10</xsl:variable>
<xsl:template match="/">
<html>
<head>
<title>Msn Chat History</title>
<style type="text/css">
body,td
{
font-size:14px;
}
.FirstCSS
{
color:#003366;
background-color:#FFFFFF;
}
.PagesCss
{
color:#003366;
font-size:13px;
}
</style>
<script langauge="javascript">
<xsl:comment>
<![CDATA[
var CurrentPage = 1;
var PageCount = 10;
function InitMessage()
{
LblMessage.innerHTML = "[Totle: "+ GetTotlePage() +" ,Current:"+ CurrentPage +"]";
}
function GetTotlePage()
{
var XMLObj = document.XMLDocument;
var totlePage = XMLObj.documentElement.selectNodes("//Message");
if( parseInt(totlePage.length/10)*10 == totlePage.length )
totlePage = parseInt(totlePage.length/PageCount);
else
totlePage = parseInt(totlePage.length/PageCount) + 1;
return totlePage;
}
function PageChange( expr )
{
switch( expr )
{
case "F":
CurrentPage = 1;
break;
case "P":
if(CurrentPage>1)
CurrentPage -= 1;
break;
case "N":
if(CurrentPage<GetTotlePage())
CurrentPage += 1;
break;
case "L":
CurrentPage = GetTotlePage();
break;
}
var XSLObj = document.XSLDocument;
var XMLObj = document.XMLDocument;
var expr = "Message[position() < "+ CurrentPage*PageCount +" and position() > "+ (CurrentPage-1)*PageCount +"]";
document.XSLDocument.selectSingleNode("//xsl:for-each/@select").value = expr;
ConXML.innerHTML = XMLObj.documentElement.transformNode(XSLObj);
LblMessage.innerHTML = "[Totle: "+ GetTotlePage() +" ,Current:"+ CurrentPage +"]";
}
]]>
</xsl:comment>
</script>
</head>
<body class="document_body" onload="InitMessage()">
<h1>
<xsl:value-of select="Log/Message/From/User/@FriendlyName"/>
Chat With
<xsl:value-of select="Log/Message/To/User/@FriendlyName"/>
</h1>
<div id="ConXML">
<xsl:apply-templates select="Log"></xsl:apply-templates>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="Log">
<table width="100%" cellspacing="1" cellpadding="1" border="0" bgcolor="#6699AA">
<tr bgcolor="#DDDDDD">
<td>SessionID</td>
<td>From</td>
<td>To</td>
<td>Time</td>
<td>Text</td>
</tr>
<xsl:for-each select="Message[position() < $PageCount]">
<xsl:sort order="ascending" select="@SessionID" data-type="number"></xsl:sort>
<tr class="FirstCSS">
<td>
<xsl:value-of select="@SessionID"/>
</td>
<td>
<xsl:value-of select="From/User/@FriendlyName"/>
</td>
<td>
<xsl:value-of select="To/User/@FriendlyName"/>
</td>
<td>
<xsl:value-of select="@Time"/>
</td>
<td>
<xsl:value-of select="string(Text)"/>
</td>
</tr>
</xsl:for-each>
<tr bgcolor="#DDDDDD">
<td colspan="5" align="right">
<span class="PagesCss">
<span id="LblMessage"></span>
[<span onclick="PageChange('F')" style="cursor:hand"> First </span>]
[<span onclick="PageChange('P')" style="cursor:hand"> Previous </span>]
[<span onclick="PageChange('N')" style="cursor:hand"> Next </span>]
[<span onclick="PageChange('L')" style="cursor:hand"> Last </span>]
</span>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="PageCount">10</xsl:variable>
<xsl:template match="/">
<html>
<head>
<title>Msn Chat History</title>
<style type="text/css">
body,td
{
font-size:14px;
}
.FirstCSS
{
color:#003366;
background-color:#FFFFFF;
}
.PagesCss
{
color:#003366;
font-size:13px;
}
</style>
<script langauge="javascript">
<xsl:comment>
<![CDATA[
var CurrentPage = 1;
var PageCount = 10;
function InitMessage()
{
LblMessage.innerHTML = "[Totle: "+ GetTotlePage() +" ,Current:"+ CurrentPage +"]";
}
function GetTotlePage()
{
var XMLObj = document.XMLDocument;
var totlePage = XMLObj.documentElement.selectNodes("//Message");
if( parseInt(totlePage.length/10)*10 == totlePage.length )
totlePage = parseInt(totlePage.length/PageCount);
else
totlePage = parseInt(totlePage.length/PageCount) + 1;
return totlePage;
}
function PageChange( expr )
{
switch( expr )
{
case "F":
CurrentPage = 1;
break;
case "P":
if(CurrentPage>1)
CurrentPage -= 1;
break;
case "N":
if(CurrentPage<GetTotlePage())
CurrentPage += 1;
break;
case "L":
CurrentPage = GetTotlePage();
break;
}
var XSLObj = document.XSLDocument;
var XMLObj = document.XMLDocument;
var expr = "Message[position() < "+ CurrentPage*PageCount +" and position() > "+ (CurrentPage-1)*PageCount +"]";
document.XSLDocument.selectSingleNode("//xsl:for-each/@select").value = expr;
ConXML.innerHTML = XMLObj.documentElement.transformNode(XSLObj);
LblMessage.innerHTML = "[Totle: "+ GetTotlePage() +" ,Current:"+ CurrentPage +"]";
}
]]>
</xsl:comment>
</script>
</head>
<body class="document_body" onload="InitMessage()">
<h1>
<xsl:value-of select="Log/Message/From/User/@FriendlyName"/>
Chat With
<xsl:value-of select="Log/Message/To/User/@FriendlyName"/>
</h1>
<div id="ConXML">
<xsl:apply-templates select="Log"></xsl:apply-templates>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="Log">
<table width="100%" cellspacing="1" cellpadding="1" border="0" bgcolor="#6699AA">
<tr bgcolor="#DDDDDD">
<td>SessionID</td>
<td>From</td>
<td>To</td>
<td>Time</td>
<td>Text</td>
</tr>
<xsl:for-each select="Message[position() < $PageCount]">
<xsl:sort order="ascending" select="@SessionID" data-type="number"></xsl:sort>
<tr class="FirstCSS">
<td>
<xsl:value-of select="@SessionID"/>
</td>
<td>
<xsl:value-of select="From/User/@FriendlyName"/>
</td>
<td>
<xsl:value-of select="To/User/@FriendlyName"/>
</td>
<td>
<xsl:value-of select="@Time"/>
</td>
<td>
<xsl:value-of select="string(Text)"/>
</td>
</tr>
</xsl:for-each>
<tr bgcolor="#DDDDDD">
<td colspan="5" align="right">
<span class="PagesCss">
<span id="LblMessage"></span>
[<span onclick="PageChange('F')" style="cursor:hand"> First </span>]
[<span onclick="PageChange('P')" style="cursor:hand"> Previous </span>]
[<span onclick="PageChange('N')" style="cursor:hand"> Next </span>]
[<span onclick="PageChange('L')" style="cursor:hand"> Last </span>]
</span>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>