用XSL和ASP实现分页功能

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

asp文件大致结构:

<%@ 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

%>

load进来的xml数据是这样的:

<?xml version="1.0" encoding="GB2312" ?>

<root>

<function>

<PO>里面的标签在后面的xsl文件里被"<xsl:for-each>"</PO>

<PO>……………………</PO>

<PO>……………………</PO>

<PO>……………………</PO>

</function>

</root>

------------------------------------

xsl文件的内容:

<?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"/><!-- 嵌入头模板,尾页模板 -->

<xsl:param name="yd">7</xsl:param><!-- 调用二级导航条所用参数 -->

<xsl:param name="page"> <xsl:value-of select="count(//PO)"/></xsl:param>

<!-- 定义根模板 -->

<xsl:template match="/">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>

<link rel="stylesheet" type="text/css" href="include/style.css"/>

<title>结果列表</title>

</head>

<body leftMargin="0" topMargin="0">

<xsl:call-template name="ydtitle"/>

<div align="center">

<xsl:apply-templates select="root/function"/>

<!-- 匹配function模板 -->

</div>

<xsl:call-template name="end"/>

</body>

</html>

</xsl:template>

<!-- 定义function模板 -->

<xsl:template match="function">

<!-- ---------------翻页链接开始----------- -->

<xsl:variable name="pagesize">5</xsl:variable><!-- 是分页参数 -->

<xsl:choose>

<xsl:when test="/root/session/page[text()!=""]">

<!-- 进入一级choose的一个when条件分支!!!!!

-------------进入此分支,证明用户已有翻页操作-------------- -->

<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">

<!-- 进入二级choose!!! -->

<xsl:choose>

<!-- ①id小于等于0的情况,显示最后一页。-->

<xsl:when test="$pid&lt;1">

<a>

<xsl:attribute name="href">

search_jieguo.asp?id=<xsl:value-of select="count(//PO)"/>

</xsl:attribute>[ 首页 ]

</a>

<a title="前一页">

<xsl:attribute name="href">

search_jieguo.asp?id=<xsl:value-of select="$size*2"/>

</xsl:attribute>[ <<< ]

</a>

<a title="后一页">[ >>> ]

</a>

<a>[ 尾页 ]</a>

</xsl:when>

<!-- ②id位于[0~pagesize]之间的情况,前页正常,后页无。 -->

<xsl:when test="$pid&lt;($size + 1) and $pid&gt;0">

<a>

<xsl:attribute name="href">

search_jieguo.asp?id=<xsl:value-of select="count(//PO)"/>

</xsl:attribute>[ 首页 ]

</a>

<a title="前一页">

<xsl:attribute name="href">

search_jieguo.asp?id=<xsl:value-of select="$pid+$size"/>

</xsl:attribute>[ <<< ]

</a>

<a title="后一页">[ >>> ] </a>

<a>[ 尾页 ]</a>

</xsl:when>

<!-- ③id位于[pagesize~count]之间的情况,前页无,后页正常。 -->

<xsl:when test="$pid&lt;count(//PO) and $pid&gt;(count(//PO)-$size)">

<a>

<xsl:attribute name="href">

search_jieguo.asp?id=<xsl:value-of select="count(//PO)"/>

</xsl:attribute>[ 首页 ]

</a>

<a title="前一页">

<xsl:attribute name="href">

search_jieguo.asp?id=<xsl:value-of select="count(//PO)"/>

</xsl:attribute>[ <<< ]

</a>

<a title="后一页">

<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>[ 尾页 ]

</a>

</xsl:when>

<!-- ④id等于count的情况,显示首页页。 -->

<xsl:when test="$pid=count(//PO)">

<a>[ 首页 ]</a>

<a title="前一页">[ <<< ] </a>

<a title="后一页">

<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>[ 尾页 ]

</a>

</xsl:when>

&

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航