xml 排序,分页
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="text/xsl" href="pages.xsl" ?>
<BlueIdea>
<team>
<blue_ID>01</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.0.1</blue_time>
<blue_class>第八组</blue_class>
</team>
<team>
<blue_ID>02</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2001.0.1</blue_time>
<blue_class>第五组</blue_class>
</team>
<team>
<blue_ID>03</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2005.0.1</blue_time>
<blue_class>第二组</blue_class>
</team>
<team>
<blue_ID>04</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.0.1</blue_time>
<blue_class>第一组</blue_class>
</team>
<team>
<blue_ID>05</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.0.1</blue_time>
<blue_class>第一组</blue_class>
</team>
<team>
<blue_ID>06</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.0.1</blue_time>
<blue_class>第二组</blue_class>
</team>
<team>
<blue_ID>07</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.0.1</blue_time>
<blue_class>第一组</blue_class>
</team>
<team>
<blue_ID>08</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.0.1</blue_time>
<blue_class>第三组</blue_class>
</team>
<team>
<blue_ID>09</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2005.10.31</blue_time>
<blue_class>第一组</blue_class>
</team>
<team>
<blue_ID>10</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.05.1</blue_time>
<blue_class>第三组</blue_class>
</team>
<team>
<blue_ID>11</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.03.1</blue_time>
<blue_class>第一组</blue_class>
</team>
<team>
<blue_ID>12</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.02.1</blue_time>
<blue_class>第一组</blue_class>
</team>
<team>
<blue_ID>13</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.10.1</blue_time>
<blue_class>第四组</blue_class>
</team>
<team>
<blue_ID>14</blue_ID>
<blue_name>小李</blue_name>
<blue_text>主题一</blue_text>
<blue_time>2002.10.1</blue_time>
<blue_class>第十组</blue_class>
</team>
</BlueIdea>
-------pages.xsl---------------------------------------------
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<title>XML演示范例 (分页 与 排序)</title>
<style>
body,BlueIdea,team,blue_ID,blue_name,blue_text,blue_time,blue_class{ font: 12px "宋体", "Arial", "Times New Roman"; }
table { font-size: 12px; border: 0px double; border-color: #99CC99 #99CC99 #CCCCCC #CCCCCC; cellpadding:3;cellspacing:3; bgcolor:#eeeeee; text-decoration: blink}
span { font-size: 12px; color: red; }
.keybutton { cursor:hand; font-size: 12px; color: #003300; background: #ffffff; border: 0px solid;}
</style>
<script>
function taxis(x)
{
var temp = 0;
stylesheet=document.XSLDocument;
source=document.XMLDocument;
temp=parseInt(document.forms[0].text5.value);
temp++;
if(temp%2==0){
x="-"+x;
}else{
x=x;
}
document.forms[0].text5.value = temp;
sortField=document.XSLDocument.selectSingleNode("//@order-by");
sortField.value=x;
Layer1.innerHTML=source.documentElement.transformNode(stylesheet);
}
</script>
<script>
<xsl:comment>
<![CDATA[
var OnePageNum=5; //每页显示五条
var PageNum=1; //当前页码
var XMLPageNum=1; //xml文件总的页码
function pages(Num)
{
stylesheet=document.XSLDocument; //获取值xml的所有值?
source=document.XMLDocument; //获取值xml的所有值?
nodes=source.documentElement.childNodes;//获取所有子结点集?
len=nodes.length; //计算结点的个数,并把值赋给len
for(i=1;i<=(len/OnePageNum);i++); //计算出共有几页
if(len%OnePageNum!=0){
XMLPageNum=i; //计算出总的页码并把值传给 XMLPageNum
}else{
XMLPageNum=i-1;
}
var firstNum=0; //每页显示的第一条,给初值为0
var lastNume=0; //每页显示的最后一条,给初值为0
if (Num=="first") {PageNum=1;} //如果传入的是第一页,则执行这个语句,赋给当前页码的值为1
if (Num=="previous") {if (PageNum>1) PageNum -=1;} //判断
if (Num=="next") {
if (PageNum<XMLPageNum) {
PageNum +=1;
}
} //判断
if (Num=="last") {PageNum =XMLPageNum;} //判断
if (Num!="last"&&Num!="next"&&Num!="previous"&&Num!="first"){
var temp=parseInt(document.forms[0].text4.value);
if(temp<=XMLPageNum&&temp>=1&&temp==document.forms[0].text4.value){
PageNum=temp;
}else{
alert("你的输入不合法,请重新输入");
document.forms[0].text4.value="";
document.forms[0].text4.focus();
}
}
sortField=document.XSLDocument.selectSingleNode("//@expr");
firstNum=OnePageNum*(PageNum-1)+1; //显示的第一条的位置
lastNum=OnePageNum*(PageNum-1)+OnePageNum; //显示的最后一条的位置
text="childnumber(this)>="+firstNum+" & childnumber(this)<="+lastNum;//
sortField.value=text; //
Layer1.innerHTML=source.documentElement.transformNode(stylesheet);
document.forms[0].text1.value=XMLPageNum;
document.forms[0].text2.value=len;
document.forms[0].text3.value=PageNum;
document.forms[0].text4.value="";
}
]]>
</xsl:comment>
</script>
</head>
<body onLoad="pages('first');">
<p align="center"><span>XML演示范例 (分页 与 排序)</span></p>
<form>
<table align="center" width="500" >
<tr>
<td>
<button id="cmdfirstPage" class="keybutton" onclick="pages('first');" >首页</button>
<button id="cmdpreviousPage" class="keybutton" onclick="pages('previous');" >上一页</button>
<button id="cmdnextPage" class="keybutton" onclick="pages('next');">下一页</button>
<button id="cmdlastPage" class="keybutton" onclick="pages('last');">尾页</button>
共<input type="text" id="text1" readOnly="true" size="1" maxLength="1"/>页
共<input type="text" id="text2" readOnly="true" size="1" maxLength="1"/>条记录
当前第<input type="text" id="text3" readOnly="true" size="1" maxLength="1"/>页
</td>
</tr>
<tr>
请输入跳转页码:<input type="text" id="text4" size="3" maxLength="3" /><button id=" " class="keybutton" onclick="pages('2');" >提交</button>
</tr>
</table>
<input type="hidden" name="text5" value="1" />
</form>
<div id="Layer1" name="Layer1"> <xsl:apply-templates select="BlueIdea" /></div>
</body>
</html>
</xsl:template>
<xsl:template match="BlueIdea">
<table width="500" border="1" align="center" cellpadding="1" cellspacing="1" bordercolordark="#ffffff" bordercolorlight="#ADAAAD">
<tr bgcolor="#FFCC99" align="center">
<td style="cursor:s-resize" onClick="taxis('blue_ID')">编号</td>
<td style="cursor:s-resize" onClick="taxis('blue_name')">姓名</td>
<td style="cursor:s-resize" onClick="taxis('blue_text')">主题</td>
<td style="cursor:s-resize" onClick="taxis('blue_time')">发表时间</td>
<td style="cursor:s-resize" onClick="taxis('blue_class')">归类</td>
</tr>
<xsl:apply-templates select="team" order-by="blue_ID"/>
</table>
</xsl:template>
<xsl:template match="team">
<xsl:if expr="childnumber(this)>=1 ">
<tr align="center">
<xsl:apply-templates select="blue_ID" />
<xsl:apply-templates select="blue_name" />
<xsl:apply-templates select="blue_text" />
<xsl:apply-templates select="blue_time" />
<xsl:apply-templates select="blue_class" />
</tr>
</xsl:if>
</xsl:template>
<xsl:template match="blue_ID">
<td bgcolor="#eeeeee">
<xsl:value-of />
</td>
</xsl:template>
<xsl:template match="blue_name">
<td>
<xsl:value-of />
</td>
</xsl:template>
<xsl:template match="blue_text">
<td>
<xsl:value-of />
</td>
</xsl:template>
<xsl:template match="blue_time">
<td>
<xsl:value-of />
</td>
</xsl:template>
<xsl:template match="blue_class">
<td>
<xsl:value-of />
</td>
</xsl:template>
</xsl:stylesheet>