以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (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=45570)


--  作者:hexun831012
--  发布时间:4/17/2007 2:39:00 PM

--  全世界最好的XSL分页
全世界最好的XSL分页是用XPath,而不是隐藏
本文以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 omit-xml-declaration="yes"/>
 <!--Declare Current Page-->
 <xsl:param name="current">1</xsl:param>
 <!--Declare Page Size-->
 <xsl:param name="page">10</xsl:param>
 <!--HTML Template-->
 <xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
    <title>XSL Paging</title>
    <style type="text/css">*{font-family:Tahoma;font-size:9pt}a{padding:1px}div{text-indent:12px}</style>
    <script type="text/javascript">function paging(page){var xmlDocument=document.XMLDocument;var xslDocument=document.XSLDocument;xslDocument.selectNodes("xsl:stylesheet/xsl:template[@match='/']").removeAll();xslDocument.selectSingleNode("xsl:stylesheet/xsl:param[@name='current']").text=page;document.body.innerHTML=xmlDocument.transformNode(xslDocument);}</script>
   </head>
   <body>
    <xsl:apply-templates/>
   </body>
  </html>
 </xsl:template>
 <!--RSS Template-->
 <xsl:template match="rss">
  <xsl:apply-templates select="channel[position() &gt;= ($current - 1) * $page and position() &lt;= $current * $page]"/>
  <xsl:call-template name="page"/>
 </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>
 <!--Page Template-->
 <xsl:template name="page">
  <xsl:for-each select="channel[position() mod $page = 1]">
   <a href="javascript:paging({position()})">
    <xsl:value-of select="position()"/>
   </a>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>


--  作者:hexun831012
--  发布时间:4/17/2007 2:42:00 PM

--  
申请精华
--  作者:Qr
--  发布时间:4/17/2007 5:48:00 PM

--  
有点看头,改天慢慢烟酒!
--  作者:lit0302
--  发布时间:4/20/2007 9:46:00 PM

--  hehe
大哥,我怎么function paging(page)功能没实现啊,就是没实现翻页的功能啊,我用的是其他xml的。
路人甲乙丙
上海 恩雅
离骚
屈原
国殇
屈原
偶然与必然
刘柳
1 2 3
--  作者:lit0302
--  发布时间:4/20/2007 9:48:00 PM

--  有消息回复我
我的邮箱lit0302@126.com,有答案回我啊。
能不能实现说声,谢谢
--  作者:hexun831012
--  发布时间:4/21/2007 9:33:00 AM

--  
本文只适用于RSS,要是其他格式xml,当然要改改了
--  作者:hexun831012
--  发布时间:4/25/2007 5:07:00 PM

--  
重法全世界最好的分页,支持firefox啦!!!
<?xml version="1.0" encoding="utf-8"?>
<!--Copyright&copy; 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" />
 <!--Declare Current Page-->
 <xsl:param name="page">1</xsl:param>
 <!--HTML Template-->
 <xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
    <title>
     <xsl:value-of select="comment()" />
    </title>
    <style type="text/css">
body
{
 font-family: Tahoma;
 font-size: 9pt;
}
a
{
 padding-right: 1px;
}
b
{
 padding-right: 1px;
}
p
{
 margin: 0px 0px 0px 16px;
}
    </style>
    <script type="text/javascript">
function loadXml(xmlSource)
{
 var xmlDocument = document.implementation.createDocument("", "", null);
 xmlDocument.async = false;
 xmlDocument.load(xmlSource);
 return xmlDocument;
}
function loadXsl(xmlDocument)
{
 var xslDocument = new XSLTProcessor();
 xslDocument.importStylesheet(xmlDocument);
 return xslDocument;
}
function paging(page)
{
 if(window.ActiveXObject)
 {
  var xmlDocument = document.XMLDocument;
  var xslDocument = document.XSLDocument;
  xslDocument.getElementsByTagName("xsl:param")[0].text = page;
  var template = xslDocument.getElementsByTagName("xsl:template")[0];
  if(template.attributes[0].value == "/")
  {
   template.parentNode.removeChild(template);
  }
  document.getElementById("rss").parentNode.innerHTML = xmlDocument.transformNode(xslDocument);
 }
 else
 {
  var xmlDocument = loadXml(window.location);
  var xslDocument = loadXml("page.xsl");
  xslDocument.getElementsByTagName("param")[0].textContent = page;
  xslDocument.documentElement.removeChild(xslDocument.getElementsByTagName("template")[0]);
  var rss = document.getElementById("rss");
  rss.parentNode.replaceChild(loadXsl(xslDocument).transformToFragment(xmlDocument, document), rss);
 }
}
    </script>
   </head>
   <body>
    <xsl:apply-templates />
   </body>
  </html>
 </xsl:template>
 <!--RSS Template-->
 <xsl:template match="rss">
  <div id="rss">
   <xsl:apply-templates select="channel[position() &gt;= 10 * ($page - 1) and position() &lt;= 10 * $page]" />
   <xsl:apply-templates select="channel[position() mod 10 = 1]" mode="page" />
  </div>
 </xsl:template>
 <!--Channel Template-->
 <xsl:template match="channel">
  <a href="{link}">
   <xsl:value-of select="title" />
  </a>
  <p>
   <xsl:value-of select="description" />
  </p>
 </xsl:template>
 <!--Page Template-->
 <xsl:template match="channel" mode="page">
  <xsl:choose>
   <xsl:when test="position() != $page">
    <a href="javascript:paging({position()})">
     <xsl:value-of select="position()" />
    </a>
   </xsl:when>
   <xsl:otherwise>
    <b>
     <xsl:value-of select="position()" />
    </b>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
</xsl:stylesheet>
--  作者:lovesky20008
--  发布时间:5/25/2007 10:28:00 PM

--  
ding
--  作者:wlpx
--  发布时间:5/27/2007 11:08:00 AM

--  顶!我能看出来是好东西,但还有点看不明白。
楼主,你发的这是XSL文件中的内容吧,但XML呢?或者说是咱自己编辑的XML文件,如何挂到这上面啊。

我问是的如何把同一目录的,想“翻译的”XML的各个标签,对应到这个XSL文件中啊?


--  作者:wlpx
--  发布时间:5/27/2007 11:32:00 AM

--  
我的做法是,在Dreamweaver8 中新建了一个XSL整页,然后用你发出来的命令复盖所有他自动生成的命令,只是把utf-8改成了gb2312。然后自己编一个XSL文件,并绑定了上去。可是浏览的时候没有分页啊,我做了16组,这16组的所有内容都按顺序显示了出来。

--  作者:wlpx
--  发布时间:5/27/2007 11:51:00 AM

--  
上文写错了,是:然后自己编一个XML文件,并绑定了上去。
--  作者:dgsd22
--  发布时间:6/14/2007 12:33:00 PM

--  
请问一下楼主,

<xsl:apply-templates select="channel[position() mod 10 = 1]" mode="page" />

这句是怎么实现页码排列的?


--  作者:hexun831012
--  发布时间:6/27/2007 4:40:00 PM

--  
说实话,这种xsl分页的性能的确相当好,但是我自己还是发现一个问题,由于firefox没有缓存机制,就不能通过类似IE中的document.XMLDocument返回当前文档,只能重新读取源文件再进行转换,那么这样的分页的性能在firefox中就显得相当的差,尤其是xml源文件中的数据是通过读取数据库动态生成的时候,不得不说,firefox的确完全遵循了W3C的标准,但W3C的标准在实际运行中的可行性和性能就有待商榷了,微软就是微软,虽然微软的XML是通过COM实现的,但是MSXML支持很多在实际运行中非常有用而且有效的方法,比如MSXML中还支持XSL过程高速缓存,为多次转换节约了大量的时间和内存,firefox不能死看着标准不放,它需要走的路还很长...
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms