新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → xsl+xml分页问题,高手们进啊!!!急!!! 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5433 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: xsl+xml分页问题,高手们进啊!!!急!!! 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     johnlee1006 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:61
      门派:XML.ORG.CN
      注册:2007/9/13

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给johnlee1006发送一个短消息 把johnlee1006加入好友 查看johnlee1006的个人资料 搜索johnlee1006在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看johnlee1006的博客楼主
    发贴心情 xsl+xml分页问题,高手们进啊!!!急!!!

    我现在在做的项目用XSL读取XML的值并显示分页,在坛子里泡了几天做出来了一个,但是不支持firefox,没法子只能重写了,但是遇到点问题,请大哥们帮忙,我是照“hexun831012”大哥的例子改的,但是XML文件不太一样,里边多了一层节点,所以数据显示是上下两部分,现在上边的可以翻页,但下部分就不行,如果去掉控制上部分的翻页,下部分就能翻了,如何让它,点翻页时同时翻啊,拜托,各位帮忙啊。
    代码:
    test.xml:
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="test.xsl"?>
    <rss version="2.0">
    <result>
    <commend>
    <channel>
        <link>http://www.google.com</link>
        <title>标题1</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题2</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题3</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题4</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题5</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题6</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题7</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题8</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题9</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题10</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题11</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题12</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题13</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题14</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题15</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    </commend>
    <most>
    <channel>
        <link>http://www.google.com</link>
        <title>标题16</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题17</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题18</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题19</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题20</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题21</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题22</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题23</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题24</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题25</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题26</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题27</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题28</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题29</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    <channel>
        <link>http://www.google.com</link>
        <title>标题30</title>
        <author>作者</author>
        <category>xml</category>
        <pubDate>Thu,30 Nov 2006</pubDate>
        <guid>http://www.google.com</guid>
        <description><![CDATA[*************************]]></description>
    </channel>
    </most>
    </result>
    </rss>


    test.xsl:
    <?xml version="1.0" encoding="utf-8"?>
    <!--Copyright(C) 2003-2007 Hexsoft.org, All Right Reserved.-->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="no" omit-xml-declaration="yes" />
    <!--Page Size-->
    <xsl:param name="page">5</xsl:param>
    <xsl:param name="nMost">5</xsl:param>

    <!--HTML Template-->
    <xsl:template match="/">
      <html version="1.0" xmlns="http://www.w3.org/1999/xhtml">
       <head>
        <style type="text/css">
    body
    {
    font-family: Tahoma;
    font-size: 9pt;
    }
        </style>
        <script type="text/javascript">
    var page;
    function paging(index)
    {
    if(page == null)
    {
      page = document.getElementById("1");
    }
    page.style.display = "none";
    page = document.getElementById(index);
    page.style.display = "";
    }
        </script>
       </head>
       <body>
        <xsl:apply-templates select="rss" />
       </body>
      </html>
    </xsl:template>
    <!--RSS Template-->
    <xsl:template match="commend">
       <div id="commend">
         <xsl:apply-templates select="channel[position() mod $page = 1]" mode="page" />
      </div>
    </xsl:template>
      <xsl:template match="most">
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        <div id="most">
        <xsl:apply-templates select="channel[position() mod $nMost = 1]" mode="nMost" />
      <div>
       <xsl:apply-templates select="channel[position() mod $nMost = 1]" mode="index" />
      </div>
      </div>
    </xsl:template>
    <!--Page Template-->
    <xsl:template match="channel" mode="page">
      <div id="{position()}">
       <xsl:if test="position() != 1">
        <xsl:attribute name="style">display:none</xsl:attribute>
       </xsl:if>
       <xsl:apply-templates select=". | following-sibling::channel[position() &lt; $page]" />
      </div>
    </xsl:template>
    <xsl:template match="channel" mode="nMost">
      <div id="{position()}">
       <xsl:if test="position() != 1">
        <xsl:attribute name="style">display:none</xsl:attribute>
       </xsl:if>
       <xsl:apply-templates select=". | following-sibling::channel[position() &lt; $nMost]" />
      </div>
    </xsl:template>
    <!--Index Template-->
    <xsl:template match="channel" mode="index">
      <a href="javascript:paging({position()})">
       <xsl:value-of select="position()" />
      </a>
    </xsl:template>
    <!--Channel Template-->
    <xsl:template match="channel">
      <a href="{link}">
       <xsl:value-of select="title" />
      </a>
      <div>
       <xsl:value-of select="description" />
      </div>
    </xsl:template>
    </xsl:stylesheet>


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/9/13 17:53:00
     
     hexun831012 帅哥哟,离线,有人找我吗?天秤座1983-10-12
      
      
      威望:1
      等级:研二(Pi-Calculus看得一头雾水)(版主)
      文章:800
      积分:5114
      门派:XML.ORG.CN
      注册:2006/12/8

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给hexun831012发送一个短消息 把hexun831012加入好友 查看hexun831012的个人资料 搜索hexun831012在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看hexun831012的博客2
    发贴心情 
    不好意思,我以前发的版本对RSS的结构理解有些问题,马上重发一个给你
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/9/14 8:43:00
     
     hexun831012 帅哥哟,离线,有人找我吗?天秤座1983-10-12
      
      
      威望:1
      等级:研二(Pi-Calculus看得一头雾水)(版主)
      文章:800
      积分:5114
      门派:XML.ORG.CN
      注册:2006/12/8

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给hexun831012发送一个短消息 把hexun831012加入好友 查看hexun831012的个人资料 搜索hexun831012在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看hexun831012的博客3
    发贴心情 
    XSL:
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:param name="size">10</param>
     <xsl:template match="rss">
      <html version="1.0" xmlns="http://www.w3.org/1999/xhtml">
       <head>
        <title>XSL分页</title>
        <style type="text/css">
        </style>
        <script type="text/javascript" src="script.js"></script>
       </head>
       <body>
        <xsl:apply-templates select="channel" />
       </body>
      </html>
     </xsl:template>
     <xsl:template match="channel">
      <xsl:apply-templates select="item[position() mod $size = 1]" mode="page" />
      <div class="rssPage">
       <xsl:apply-templates select="item[position() mod $size = 1]" mode="index" />
      </div>
     </xsl:template>
     <xsl:template match="item" mode="page">
      <div id="page{position()}" class="rss">
       <xsl:if test="position() != 1">
        <xsl:attribute name="style">display:none;</xsl:attribute>
       </xsl:if>
       <xsl:apply-templates select=". | following-sibling::item[position() &lt; 10]"/>
      </div>
     </xsl:template>
     <xsl:template match="item" mode="index">
      <a id="index{position()}" href="javascript:pageRss({position()})">
       <xsl:if test="position() = 1">
        <xsl:attribute name="style">font-weight:bold;</xsl:attribute>
       </xsl:if>
       <xsl:value-of select="position()"/>
      </a>
     </xsl:template>
     <xsl:template match="item">
      <a href="{link}" target="_blank">
       <xsl:value-of select="title"/>
      </a>
      <div>
       <xsl:value-of select="description"/>
      </div>
     </xsl:template>
    </xsl:stylesheet>
    Javascript:
    var page;
    //Current Index
    var index;
    function pageRss(number)
    {
     if(page == null || index == null)
     {
      page = document.getElementById("page1");
      index = document.getElementById("index1");
     }
     page.style.display = "none";
     index.style.fontWeight = "";
     page = document.getElementById("page" + number);
     index = document.getElementById("index" + number);
     page.style.display = "";
     index.style.fontWeight = "bold";
    }
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/9/14 8:45:00
     
     hexun831012 帅哥哟,离线,有人找我吗?天秤座1983-10-12
      
      
      威望:1
      等级:研二(Pi-Calculus看得一头雾水)(版主)
      文章:800
      积分:5114
      门派:XML.ORG.CN
      注册:2006/12/8

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给hexun831012发送一个短消息 把hexun831012加入好友 查看hexun831012的个人资料 搜索hexun831012在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看hexun831012的博客4
    发贴心情 
    补充,这是隐藏式分页,由于缓存式分页在Mozilla Firefox下起不到好的效果,所以隐藏式分页是唯一的途径
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/9/14 8:47:00
     
     johnlee1006 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:61
      门派:XML.ORG.CN
      注册:2007/9/13

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给johnlee1006发送一个短消息 把johnlee1006加入好友 查看johnlee1006的个人资料 搜索johnlee1006在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看johnlee1006的博客5
    发贴心情 
    谢谢你对我的问题做出的回答,但是你给我的例子我跑不起来,您还是没有完全明白我的意思,我的XML里多了两层节点,所以我在一个XML中取出的值是两部分,我要对这两部分的值进行分页控制,我现在只能控制一部分翻页,而不能控制两个同时翻页,拜托大哥帮我想想办法啊
    <rss version="2.0">
    <result>
       <commend>
           <channel>
              <link>http://www.google.com</link>
              <description><![CDATA[*************************]]></description>
           </channel>
           <channel>
              <link>http://www.google.com</link>
              <description><![CDATA[*************************]]></description>
           </channel>
       </commend>
       <most>
           <channel>
              <link>http://www.google.com</link>
              <description><![CDATA[*************************]]></description>
           </channel>
              <link>http://www.google.com</link>
              <description><![CDATA[*************************]]></description>
            </channel>
        </most>
    </result>
    </rss>
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/9/14 10:17:00
     
     907941727 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:14
      积分:103
      门派:XML.ORG.CN
      注册:2008/6/24

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给907941727发送一个短消息 把907941727加入好友 查看907941727的个人资料 搜索907941727在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看907941727的博客6
    发贴心情 
    我是用这个分页的,不知道对不对
       <div id="navBar">
        <xsl:choose>
         <xsl:when test="$page = 1">
          第<xsl:value-of select="$page" />页
          共有<xsl:value-of select="$pages" />页
          共有<xsl:value-of select="$count" />条记录
         <a href="#{$page + 1}" onclick="nextPage({$page + 1})">下一页</a>::
         <a href="#{$pages}"    onclick="lastPage({$page},{$pages})">尾页</a>
         
         
         </xsl:when>
         <xsl:when test="$page = $pages">
          第<xsl:value-of select="$page" />页
          共有<xsl:value-of select="$pages" />页
          共有 条记录
         <a href="#{1}" onclick="firstPage({$page})">首页</a>::
         <a href="#{$page - 1}" onclick="prevPage({$page - 1})">上一页</a>::
         <a href="#{$page + 1}" onclick="nextPage({$page + 1})">下一页</a>::
         <a href="#{$pages}"    onclick="lastPage({$page},{$pages})">尾页</a>
         </xsl:when>
         <xsl:otherwise>
          第<xsl:value-of select="$page" />页
          共有<xsl:value-of select="$pages" />页
          共有 条记录
         <a href="#{1}" onclick="firstPage({$page})">首页</a>::
         <a href="#{$page - 1}" onclick="prevPage({$page - 1})">上一页</a>::
         <a href="#{$page + 1}" onclick="nextPage({$page + 1})">下一页</a>::
         <a href="#{$pages}"    onclick="lastPage({$page},{$pages})">尾页</a>
         </xsl:otherwise>
        </xsl:choose>
       </div>
      </table>
      </div>
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/6/24 9:37:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2025/8/14 23:28:48

    本主题贴数6,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    1,765.625ms