• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

用XSL和ASP实现分页功能_xml

xml 搞代码 7年前 (2018-06-15) 167次浏览 已收录 0个评论

asp文件大致结构:
<%@ Language=VBScript %>
<!– #include file=include/lib.asp –>
<%
cc=server.MapPath(“trans.xml“)
set source=server.CreateObject(“msxml2.domdocument”)

http://www.gaodaima.com/34218.html用XSL和ASP实现分页功能_xml

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>

欢迎大家阅读《用XSL和ASP实现分页功能_xml》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:用XSL和ASP实现分页功能_xml

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址