用XSL和ASP實現分頁功能

來源:互聯網
上載者:User
分頁

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<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<($size + 1) and $pid>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<count(//PO) and $pid>(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>
        <!-- ⑤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>


        <!-- 正常情況 -->
<xsl:otherwise>
        <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="後一頁">
       <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:otherwise>
</xsl:choose>
   <!------------------------------------ -->
     </td>
     </tr>
    </table>
<br/>
    <! ---------遍曆符合要求的PO結點------------- -->
     <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>


<!-- 退出一級choose的一個when條件分支!!!!! -->
</xsl:when>
<!-------------使用者直接進入的狀態-------------- -->
<xsl:otherwise>
<!-- 進入一級choose的另一個when條件分支!!!!! -->
<table border="0" cellpadding="2" cellspacing="0" width="630">
<tr>
<td align="right">
  <a>[ 首頁 ]</a>
  <a title="前一頁">[ <<< ] </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>
  </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>


<!-- 退出一級choose的另一個when條件分支!!!!! -->
</xsl:otherwise>
</xsl:choose>
        <!-- --------------翻頁連結到此結束----------- -->
        <br/>
     <xsl:if test="count(//PO)=0">
     <div align="center">
     <b><img src="http://www.webjx.com/htmldata/2005-03-23/images/msg2.gif" align="absmiddle"/> </b>
     <font color="#CC0000" face="楷體CS" size="3"><b>
                     沒有符合當前條件的訂單</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="重新輸入條件詢" search.asp""/>
      </xsl:if>
    </xsl:template>
<!------------------------------------>
<xsl:template name="PO">
  <table border="1" cellpadding="2" cellspacing="0" width="100%">
    <tr>
      <td nowrap="nowrap" width="70"> 號碼</td>
      <td nowrap="nowrap" width="110"> 名稱</td>
      <td nowrap="nowrap" width="110"> 日期</td>
      <td nowrap="nowrap" width="110"> 人員</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>



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.