加载中...
查看文章
  • 仅用XSL和ASP实现分页功能(代码)
  • 作者:小乙 来源:chinaasp 添加时间:2002年12月18日 字体:
  • 80534---------------------------------

    #:" -G注意事项:

    #:" -G※本文代码可能有一些多余部分未去掉,请在阅读时忽略。

    #:" -G 一些外部include进来的文件这里就不贴上来了。

    #:" -G※小乙写xsl也不久,很多语句都不会使用,有些地方写得比较罗嗦,

    #:" -G 如果您有更好的分页代码,请多多拿来交流。

    #:" -G※适用于:用asp load进来xml代码,

    #:" -G然后用此xsl文件进行分页处理。

    #:" -G※[2001.2.19]

    #:" -G------------------------------------

    #:" -Gasp文件大致结构:

    #:" -G<%@ Language=VBScript %>

    #:" -G<!-- #include file=include/lib.asp -->

    #:" -G<%  

    #:" -Gcc=server.MapPath("trans.xml")

    #:" -Gset source=server.CreateObject("msxml2.domdocument")

    #:" -Gsource.async=false

    #:" -Gsource.load(cc)

    #:" -G

    #:" -Gxslfile=server.MapPath("index.xsl")

    #:" -Gset style=server.CreateObject("msxml2.domdocument")

    #:" -Gstyle.async=false

    #:" -Gstyle.load(xslfile)

    #:" -G

    #:" -G'Response.write source.transformNode(style)

    #:" -GResponse.write gb_html(source.transformNode(style))

    #:" -GResponse.End  

    #:" -G%>

    #:" -G------------------------------------load进来的xml数据是这样的:

    #:" -G<?xml version="1.0" encoding="GB2312" ?>  

    #:" -G<root>

    #:" -G<function>

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

    #:" -G<PO>……………………</PO>

    #:" -G<PO>……………………</PO>

    #:" -G<PO>……………………</PO>

    #:" -G</function>

    #:" -G</root>

    #:" -G

    #:" -G

    #:" -G------------------------------------

    #:" -Gxsl文件的内容:

    #:" -G

    #:" -G<?xml version="1.0" encoding="GB2312"?>

    #:" -G<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

    #:" -G<xsl:include href="include/ydzhongxin.xsl"/><!-- 嵌入头模板,尾模板 -->

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

    #:" -G<xsl:param name="page">  <xsl:&#118alue-of select="count(//PO)"/></xsl:param>

    #:" -G

    #:" -G<!-- 定义根模板 -->

    #:" -G<xsl:template match="/">

    #:" -G<html>

    #:" -G<head>

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

    #:" -G<link rel="stylesheet" type="text/css" href="include/style.css"/>

    #:" -G<title>结果列表</title>

    #:" -G</head>

    #:" -G<body leftMargin="0" topMargin="0">

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

    #:" -G

    #:" -G    <div align="center">

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

    #:" -G    <!-- 匹配function模板 -->

    #:" -G    </div>

    #:" -G

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

    #:" -G</body>

    #:" -G</html>

    #:" -G</xsl:template>

    #:" -G

    #:" -G

    #:" -G

    #:" -G<!-- 定义function模板 -->

    #:" -G<xsl:template match="function">

    #:" -G<!-- ---------------翻页链接开始----------- -->

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

    #:" -G

    #:" -G<xsl:choose>

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

    #:" -G<!-- 进入一级choose的一个when条件分支!!!!!

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

    #:" -G<xsl:variable name="page"><xsl:&#118alue-of select="/root/session/page"/></xsl:variable>

    #:" -G<table border="0" cellpadding="2" cellspacing="0" width="630">

    #:" -G  <tr>

    #:" -G    <td align="right">

    #:" -G    <!-- 进入二级choose!!! -->

    #:" -G    <xsl:choose>

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

    #:" -G    <xsl:when test="$pid<1">

    #:" -G    <a><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="count(//PO)"/></xsl:attribute>

    #:" -G[ 首 ]</a>

    #:" -G    <a title="前一页"><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$size*2"/></xsl:attribute>[ <<< ] </a>

    #:" -G    <a title="后一页">[ >>> ] </a>

    #:" -G    <a>[ 尾 ]</a>

    #:" -G    </xsl:when>

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

    #:" -G    <xsl:when test="$pid<($size + 1) and $pid>0">

    #:" -G    <a><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="count(//PO)"/></xsl:attribute>

    #:" -G[ 首 ]</a>

    #:" -G    <a title="前一页"><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$pid+$size"/></xsl:attribute>[ <<< ] </a>

    #:" -G    <a title="后一页">[ >>> ] </a>

    #:" -G    <a>[ 尾 ]</a>

    #:" -G    </xsl:when>

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

    #:" -G    <xsl:when test="$pid<count(//PO) and $pid>(count(//PO)-$size)">

    #:" -G    <a><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="count(//PO)"/></xsl:attribute>

    #:" -G[ 首 ]</a>

    #:" -G    <a title="前一页"><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="count(//PO)"/></xsl:attribute>[ <<< ] </a>

    #:" -G    <a title="后一页"><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$pid - $size"/></xsl:attribute>[ >>> ] </a>

    #:" -G    <a><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$size"/></xsl:attribute>

    #:" -G[ 尾 ]</a>

    #:" -G    </xsl:when>

    #:" -G

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

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

    #:" -G    <a>[ 首 ]</a>

    #:" -G    <a title="前一页">[ <<< ] </a>

    #:" -G    <a title="后一页"><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="count(//PO)-$size"/></xsl:attribute>[ >>> ] </a>

    #:" -G    <a><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$size"/></xsl:attribute>

    #:" -G[ 尾 ]</a>

    #:" -G    </xsl:when>

    #:" -G    <!-- ⑤id大于count的情况,显示首页。 -->

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

    #:" -G    <a>[ 首 ]</a>

    #:" -G    <a title="前一页">[ <<< ] </a>

    #:" -G    <a title="后一页"><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="count(//PO)-$size"/></xsl:attribute>[ >>> ] </a>

    #:" -G    <a><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$size"/></xsl:attribute>

    #:" -G[ 尾 ]</a>

    #:" -G    </xsl:when>

    #:" -G

    #:" -G    <!-- 正常情况 -->

    #:" -G    <xsl:otherwise>

    #:" -G    <a><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="count(//PO)"/></xsl:attribute>

    #:" -G[ 首 ]</a>

    #:" -G    <a title="前一页"><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$pid + $size"/></xsl:attribute>[ <<< ] </a>

    #:" -G    <a title="后一页"><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$pid - $size"/></xsl:attribute>[ >>> ] </a>

    #:" -G    <a><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$size"/></xsl:attribute>

    #:" -G[ 尾 ]</a>

    #:" -G    </xsl:otherwise>

    #:" -G    </xsl:choose>

    #:" -G    <!-- ---------------------------------------- -->

    #:" -G          </td>

    #:" -G          </tr>

    #:" -G        </table><br/>

    #:" -G      <!-- ---------遍历符合要求的PO结点------------- -->

    #:" -G      <xsl:for-each select="PO[position()<=$pid and position()>($pid - $size)]">

    #:" -G        <xsl:sort select="PO_ID" order="descending" data-type="number"/>

    #:" -G        <xsl:call-template name="PO"/>

    #:" -G        <br/><br/><br/>

    #:" -G      </xsl:for-each>

    #:" -G<!-- 退出一级choose的一个when条件分支!!!!! -->

    #:" -G</xsl:when>

    #:" -G<!-- ------------------用户直接进入的状态------------------ -->

    #:" -G<xsl:otherwise>

    #:" -G<!-- 进入一级choose的另一个when条件分支!!!!! -->

    #:" -G<table border="0" cellpadding="2" cellspacing="0" width="630">

    #:" -G<tr><td align="right">

    #:" -G<a>[ 首 ]</a>

    #:" -G<a title="前一页">[ <<< ] </a>

    #:" -G<a title="后一页"><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$pid - $size"/></xsl:attribute>[ >>> ] </a>

    #:" -G<a><xsl:attribute name="href">search_jieguo.asp?id=<xsl:&#118alue-of select="$size"/></xsl:attribute>

    #:" -G[ 尾 ]</a>

    #:" -G</td></tr>

    #:" -G</table><br/>

    #:" -G      <xsl:for-each select="PO[position()<=$pid and position()>($pid - $size)]">

    #:" -G        <xsl:sort select="PO_ID" order="descending" data-type="number"/>

    #:" -G        <xsl:call-template name="PO"/>

    #:" -G        <br/><br/><br/>

    #:" -G      </xsl:for-each>

    #:" -G<!-- 退出一级choose的另一个when条件分支!!!!! -->

    #:" -G</xsl:otherwise>

    #:" -G</xsl:choose>

    #:" -G    <!-- --------------翻页链接到此结束----------- -->

    #:" -G    <br/>

    #:" -G    <xsl:if test="count(//PO)=0">

    #:" -G

    #:" -G  <div align="center"><b>

    #:" -G   <img src="images/msg2.gif" align="absmiddle"/>

    #:" -G   </b><font color="#CC0000" face="楷体CS" size="3"><b>

    #:" -G   没有符合当前条件的订单</b></font>  

    #:" -G   <a><xsl:attribute name="href">lkxx.asp?po_id=<xsl:&#118alue-of select="PO_ID"/></xsl:attribute></a>

    #:" -G  </div>

    #:" -G><br/><br/>

    #:" -G<input type="button" &#118alue="重新输入条件查询" &#111nclick="location.href='search.asp'"/>

    #:" -G    </xsl:if>

    #:" -G  </xsl:template>

    #:" -G

    #:" -G

    #:" -G

    #:" -G

    #:" -G

    #:" -G

    #:" -G<!-- ------------------------------------------>

    #:" -G<xsl:template name="PO">

    #:" -G <table border="1" cellpadding="2" cellspacing="0" width="100%">

    #:" -G  <tr>  

    #:" -G   <td nowrap="nowrap" width="70"> 号码</td>

    #:" -G   <td nowrap="nowrap" width="110"> 名称</td>

    #:" -G   <td nowrap="nowrap" width="110"> 日期</td>

    #:" -G   <td nowrap="nowrap" width="110"> 人员</td>

    #:" -G  </tr>

    #:" -G  <tr>

    #:" -G<td nowrap="nowrap"> <xsl:&#118alue-of select="num"/></td>

    #:" -G<td nowrap="nowrap"> <xsl:&#118alue-of select="username"/></td>

    #:" -G<td nowrap="nowrap"> <xsl:&#118alue-of select="dt"/></td>

    #:" -G<td nowrap="nowrap"> <xsl:&#118alue-of select="men"/></td>

    #:" -G  </tr>

    #:" -G </table>

    #:" -G</xsl:template>

    #:" -G</xsl:stylesheet>80531
  • 返回页面顶端
  • 上一篇:利用ASP在线维护数据库
  • 下一篇:ASP如何获取真实IP地址
  • 返回上一页 打印本文 加入收藏
  • 页面最后更新时间:2010年3月10日