Paging functionality with XSL and ASP

Source: Internet
Author: User
Tags define exit end include sort version variable xsl
Paging

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 comes in load is like 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, last 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>
&LT;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>[Home]
</a>
<a title= "Previous page" >
<xsl:attribute name= "href" >
search_jieguo.asp?id=<xsl:value-of select= "$size *2"/>
</xsl:attribute>[<<<]
</a>
<a title= "Back Page" >[>>>]
</a>
<a>[last]</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>[Home]
</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>[last]</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>[Home]
</a>
<a title= "Previous page" >
<xsl:attribute name= "href" >
search_jieguo.asp?id=<xsl:value-of select= "Count (//po)"/>
</xsl:attribute>[<<<]
</a>
<a title= "Back 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>[last]
</a>
</xsl:when>
<!--④id equals count, displays the first page. -->
<xsl:when test= "$pid =count (//PO)" >
<a>[Home]</a>
<a title= "Previous page" >[<<<] </a>
<a title= "Back 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>[last]
</a>
</xsl:when>
<!--⑤id is larger than count, displays the first page. -->
<xsl:when test= "$pid >count (//PO)" >
<a>[Home]</a>
<a title= "Previous page" >[<<<] </a>
<a title= "Back 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>[last]
</a>
</xsl:when>


<!--normal situation-->
<xsl:otherwise>
<a>
<xsl:attribute name= "href" >
search_jieguo.asp?id=<xsl:value-of select= "Count (//po)"/>
</xsl:attribute>[Home]
</a>
<a title= "Previous page" >
<xsl:attribute name= "href" >
search_jieguo.asp?id=<xsl:value-of select= "$pid + $size"/>
</xsl:attribute>[<<<]
</a>
<a title= "Back 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>[last]
</a>
</xsl:otherwise>
</xsl:choose>
<!-------------------------------------->
</td>
</tr>
</table>
<br/>
<! ---------traversal conforming to the required PO node--------------->
<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>
<!-------------the 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>
&LT;TD align= "Right" >
<a>[Home]</a>
<a title= "Previous page" >[<<<] </a>
<a title= "Back 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>[last]
</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= "Reenter the conditional inquiry" search.asp ""/>
</xsl:if>
</xsl:template>
<!------------------------------------>
<xsl:template name= "PO" >
<table border= "1" cellpadding= "2" cellspacing= "0" width= "100%" >
<tr>
&LT;TD nowrap= "nowrap" width= "M" > Number </td>
&LT;TD nowrap= "nowrap" width= "a" > Name </td>
&LT;TD nowrap= "nowrap" width= "> Date </td>"
&LT;TD nowrap= "nowrap" width= "> Personnel </td>
</tr>
<tr>
&LT;TD nowrap= "nowrap" > <xsl:value-of select= "num"/></td>
&LT;TD nowrap= "nowrap" > <xsl:value-of select= "username"/></td>
&LT;TD nowrap= "nowrap" > <xsl:value-of select= "DT"/></td>
&LT;TD nowrap= "nowrap" > <xsl:value-of select= "Men"/></td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.