-- 作者:lit0302
-- 发布时间:4/21/2007 10:06:00 AM
-- 修改下xsl分页代码
<?xml version="1.0" encoding="gb2312" ?><!-- DWXMLSource="page.xml" --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="/"> <html> <head> <title>XML演示范例 (分页 与 排序)</title> <style type="text/css"> 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("xsl:stylesheet/xsl:sort[@select='blue_ID']"); sortField.value=x; Layer1.innerHTML=source.documentElement.transformNode(stylesheet); } </script> <script> <![CDATA[ var OnePageNum=2; //每页显示的数据数 var PageNum=1; //当前页码 var XMLPageNum=1; //总页数 function pages(Num) { stylesheet=document.XSLDocument; //获取值xml的所有值? source=document.XMLDocument; //获取值xml的所有值? nodes=source[1].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("//@test"); firstNum=OnePageNum*(PageNum-1)+1; //显示的第一条的位置 lastNum=OnePageNum*(PageNum-1)+OnePageNum; //显示的最后一条的位置 text="position()>="+firstNum+" and position()<="+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=""; } ]]> </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"> <xsl:sort order="ascending" data-type="number" select="blue_ID"></xsl:sort> </xsl:apply-templates> </table> </xsl:template> <xsl:template match="team"> <xsl:if test="position()>0 and position()<3"> <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 select="." /> </td> </xsl:template> <xsl:template match="blue_name"> <td> <xsl:value-of select="." /> </td> </xsl:template> <xsl:template match="blue_text"> <td> <xsl:value-of select="." /> </td> </xsl:template> <xsl:template match="blue_time"> <td> <xsl:value-of select="." /> </td> </xsl:template> <xsl:template match="blue_class"> <td> <xsl:value-of select="." /> </td> </xsl:template> </xsl:stylesheet> page.xml <?xml version="1.0" encoding="gb2312" ?> <?xml-stylesheet type="text/xsl" href="page.xsl" ?> <BlueIdea> <team> <blue_ID>1</blue_ID> <blue_name>Sailflying</blue_name> <blue_text>一个简单的排序</blue_text> <blue_time>2002-1-11 17:35:33</blue_time> <blue_class>XML专题</blue_class> </team> <team> <blue_ID>2</blue_ID> <blue_name>flyingbird</blue_name> <blue_text>嫁给你,是要你疼的</blue_text> <blue_time>2001-09-06 12:45:51</blue_time> <blue_class>灌水精华</blue_class> </team> <team> <blue_ID>3</blue_ID> <blue_name>苛子</blue_name> <blue_text>正则表达式在UBB论坛中的应用</blue_text> <blue_time>2001-11-23 21:02:16</blue_time> <blue_class>Web 编程精华</blue_class> </team> <team> <blue_ID>4</blue_ID> <blue_name>太乙郎</blue_name> <blue_text>年末经典分舵聚会完全手册 v0.1</blue_text> <blue_time>2000-12-08 10:22:48</blue_time> <blue_class>论坛灌水区</blue_class> </team> <team> <blue_ID>5</blue_ID> <blue_name>mmkk</blue_name> <blue_text>Asp错误信息总汇</blue_text> <blue_time>2001-10-13 16:39:05</blue_time> <blue_class>javascript脚本</blue_class> </team> <team> <blue_ID>3</blue_ID> <blue_name>苛子</blue_name> <blue_text>正则表达式在UBB论坛中的应用</blue_text> <blue_time>2001-11-23 21:02:16</blue_time> <blue_class>Web 编程精华</blue_class> </team> <team> <blue_ID>4</blue_ID> <blue_name>太乙郎</blue_name> <blue_text>年末经典分舵聚会完全手册 v0.1</blue_text> <blue_time>2000-12-08 10:22:48</blue_time> <blue_class>论坛灌水区</blue_class> </team> <team> <blue_ID>5</blue_ID> <blue_name>mmkk</blue_name> <blue_text>Asp错误信息总汇</blue_text> <blue_time>2001-10-13 16:39:05</blue_time> <blue_class>javascript脚本</blue_class> </team> </BlueIdea>
|