以文本方式查看主题

-  W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWL  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  重发XSL分页  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=49164)


--  作者:hexun831012
--  发布时间:6/28/2007 4:09:00 PM

--  重发XSL分页
鉴于firefox缓存机制问题,换了一种方式实现,还是以RSS为例

<?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">10</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="rss">
  <xsl:apply-templates select="channel[position() mod $page = 1]" mode="page" />
  <div>
   <xsl:apply-templates select="channel[position() mod $page = 1]" mode="index" />
  </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>
 <!--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>


--  作者:hexun831012
--  发布时间:6/28/2007 4:13:00 PM

--  
申请精华
--  作者:Qr
--  发布时间:6/28/2007 4:23:00 PM

--  
实际上就是一次性将XML读到浏览器,通过XSL将数据按须转换到不同的DIV中,使用javascript+css方式,显示和隐藏DIV来模拟分页。但如果XML数据量太大,偶觉得效果也不好,以前有做过


--  作者:hexun831012
--  发布时间:6/28/2007 6:31:00 PM

--  
的确,第一次载入很慢,但我以前写的那个不可行啊
--  作者:hexun831012
--  发布时间:6/29/2007 10:38:00 AM

--  
我试了一下,512K的1500条纪录在IE下大约1s,在FF下1.2s,还算可以
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
66.406ms