Paging functionality with XSL and ASP only
Last Update:2017-02-28
Source: Internet
Author: User
Precautions:
※ This article code may have some superfluous parts not removed, please ignore when reading.
Some of the externally included files are not posted here.
※ Small B Write XSL also soon, many statements will not be used, some places to write more wordy,
If you have a better paging code, please talk to them more.
※ Apply to: Use ASP load to enter the XML code, then use this XSL file for paging processing.
※[2001.2.19]
------------------------------------
ASP file Approximate structure:
<%@ Language=vbscript%>
<!--#include file=include/lib.asp-->
<%
Cc=server. MapPath ("Trans.xml")
Set Source=server. CreateObject ("Msxml2.domdocument")
Source.async=false
Source.load (CC)
Xslfile=server. MapPath ("index.xsl")
Set Style=server. CreateObject ("Msxml2.domdocument")
Style.async=false
Style.load (Xslfile)
' Response.Write Source.transformnode (Style)
Response.Write gb_html (Source.transformnode (style))
Response.End
%>
The XML data that------------------------------------load comes in is this:
<?xml version= "1.0" encoding= "GB2312"?>
<root>
<function>
<PO> tags in the later XSL file are "<xsl:for-each>" </PO>
<PO>........................</PO>
<PO>........................</PO>
<PO>........................</PO>
</function>
</root>
------------------------------------
The contents of the XSL file:
<?xml version= "1.0" encoding= "GB2312"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:include href= "include/ydzhongxin.xsl"/><!--embedded header template, tail template-->
<xsl:param name= "yd" >7</xsl:param><!--invoke parameters for the level two navigation bar-->
<xsl:param name= "page" > <xsl:value-of select= "Count (//po)"/></xsl:param>
<!--define root templates-->
<xsl:template match= "/" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<link rel= "stylesheet" type= "Text/css" href= "Include/style.css"/>
<title> Results List </title>
<body leftmargin= "0" topmargin= "0" >
<xsl:call-template name= "Ydtitle"/>
<div align= "center" >
<xsl:apply-templates select= "Root/function"/>
<!--matching function template-->
</div>
<xsl:call-template name= "End"/>
</body>
</xsl:template>
<!--define function templates-->
<xsl:template match= "function" >
<!-----------------page links start------------->
<xsl:variable name= "pagesize" >5</xsl:variable><!--is a paging parameter-->
<xsl:choose>
<xsl:when test= "/root/session/page[text ()!= '" >
<!--A When condition branch into the first level choose!!!!!
-------------into this branch to prove that the user has a paging operation---------------->
<xsl:variable name= "page" ><xsl:value-of select= "/root/session/page"/></xsl:variable>
<table border= "0" cellpadding= "2" cellspacing= "0" width= "630" >
<tr>
<TD align= "Right" >
<!--into Level two choose!!! -->
<xsl:choose>
<!--①id is less than or equal to 0, the last page is displayed. -->
<xsl:when test= "$pid <1" >
<a><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= count
(//PO) "/></xsl:attribute>
[First]</a>
<a title= "Previous page" ><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of
select= "$size *2"/></xsl:attribute>[<<<] </a>
<a title= "Next page" >[>>>] </a>
<a>[Tail]</a>
</xsl:when>
<!--②id is located between [0~pagesize], the front page is normal, and the back page is none. -->
<xsl:when test= "$pid < ($size + 1) and $pid >0" >
<a><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= count
(//PO) "/></xsl:attribute>
[First]</a>
<a title= "Previous page" ><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of
select= "$pid + $size"/></xsl:attribute>[<<<] </a>
<a title= "Next page" >[>>>] </a>
<a>[Tail]</a>
</xsl:when>
<!--③id is located between [Pagesize~count], front page none, back Page normal. -->
<xsl:when test= "$pid <count (//PO) and $pid > (count (//PO)-$size)" >
<a><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= count
(//PO) "/></xsl:attribute>
[First]</a>
<a title= "Previous page" ><xsl:attribute name= "href >search_jieguo.asp?id=<xsl:value-of select=" Count
(//PO) "/></xsl:attribute>[<<<] </a>
<a title= "Next page" ><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= "$pid-
$size "/></xsl:attribute>[>>>] </a>
<a><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= "$size"/></xsl: Attribute>
[Tail]</a>
</xsl:when>
<!--④id equals count, displays the home page. -->
<xsl:when test= "$pid =count (//PO)" >
<a>[First]</a>
<a title= "Previous page" >[<<<] </a>
<a title= "Next page" ><xsl:attribute name= "href >search_jieguo.asp?id=<xsl:value-of select=" Count
(//PO)-$size "/></xsl:attribute>[>>>] </a>
<a><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= "$size"/></xsl: Attribute>
[Tail]</a>
</xsl:when>
<!--⑤id is larger than count, displays the home page. -->
<xsl:when test= "$pid >count (//PO)" >
<a>[First]</a>
<a title= "Previous page" >[<<<] </a>
<a title= "Next page" ><xsl:attribute name= "href >search_jieguo.asp?id=<xsl:value-of select=" Count
(//PO)-$size "/></xsl:attribute>[>>>] </a>
<a><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= "$size"/></xsl: Attribute>
[Tail]</a>
</xsl:when>
<!--normal situation-->
<xsl:otherwise>
<a><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= count
(//PO) "/></xsl:attribute>
[First]</a>
<a title= "Previous page" ><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= "$pid +
$size "/></xsl:attribute>[<<<] </a>
<a title= "Next page" ><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= "$pid-
$size "/></xsl:attribute>[>>>] </a>
<a><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= "$size"/></xsl: Attribute>
[Tail]</a>
</xsl:otherwise>
</xsl:choose>
<!-------------------------------------------->
</td>
</tr>
</table><br/>
<!-----------Traverse the PO node---------------> that meet the requirements
<xsl:for-each select= "po[position () <= $pid and position () > ($pid-$size)]" >
<xsl:sort select= "po_id" order= "descending" data-type= "number"/>
<xsl:call-template name= "PO"/>
<br/><br/><br/>
</xsl:for-each>
<!--exit one-level choose of a condition branch!!!!! -->
</xsl:when>
<!--------------------user directly into the state-------------------->
<xsl:otherwise>
<!--another when condition branch into the first level choose!!!!! -->
<table border= "0" cellpadding= "2" cellspacing= "0" width= "630" >
<TR><TD align= "Right" >
<a>[First]</a>
<a title= "Previous page" >[<<<] </a>
<a title= "Next page" ><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= "$pid-
$size "/></xsl:attribute>[>>>] </a>
<a><xsl:attribute name= "href" >search_jieguo.asp?id=<xsl:value-of select= "$size"/></xsl: Attribute>
[Tail]</a>
</td></tr>
</table><br/>
<xsl:for-each select= "po[position () <= $pid and position () > ($pid-$size)]" >
<xsl:sort select= "po_id" order= "descending" data-type= "number"/>
<xsl:call-template name= "PO"/>
<br/><br/><br/>
</xsl:for-each>
<!--exit One-level choose another when conditional branch!!!!! -->
</xsl:otherwise>
</xsl:choose>
<!----------------Paging link to this end------------->
<br/>
<xsl:if test= "Count (//PO) =0" >
<div align= "center" ><b>
</b><font color= "#CC0000" face= "italics cs" size= "3" ><b>
There are no orders to meet the current conditions </b></font>
<a><xsl:attribute name= "href" >lkxx.asp?po_id=<xsl:value-of select= "po_id"/></xsl:attribute ></a>
</div>
><br/><br/>
<input type= "button" value= "Re-enter conditional query"/>
</xsl:if>
</xsl:template>
<!-------------------------------------------->
<xsl:template name= "PO" >
<table border= "1" cellpadding= "2" cellspacing= "0" width= "100%" >
<tr>
<TD nowrap= "nowrap" width= "M" > Number </td>
<TD nowrap= "nowrap" width= "a" > Name </td>
<TD nowrap= "nowrap" width= "> Date </td>"
<TD nowrap= "nowrap" width= "> Personnel </td>
</tr>
<tr>
<TD nowrap= "nowrap" > <xsl:value-of select= "num"/></td>
<TD nowrap= "nowrap" > <xsl:value-of select= "username"/></td>
<TD nowrap= "nowrap" > <xsl:value-of select= "DT"/></td>
<TD nowrap= "nowrap" > <xsl:value-of select= "Men"/></td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>