以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  跨浏览器的XSL排序分页,XPath版  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=69285)


--  作者:hexun831012
--  发布时间:11/9/2008 12:38:00 PM

--  跨浏览器的XSL排序分页,XPath版
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" indent="no" omit-xml-declaration="yes"/>
 <xsl:param name="page">1</xsl:param>
 <xsl:param name="sort">title</xsl:param>
 <xsl:param name="size">10</xsl:param>
 <xsl:template match="rss">
  <html version="1.0" xmlns="http://www.w3.org/1999/xhtml">
   <head>
    <title>
     <xsl:value-of select="channel/title"/>
    </title>
    <link type="application/rss+xml" href="{channel/link}" title="{channel/title}" rel="alternate"/>
    <style type="text/css">* {font-family: Tahoma; font-size: 9pt;}</style>
    <script type="text/javascript" src="/script/xml.js"></script>
    <script type="text/javascript">
     <![CDATA[function refreshXml()
{
 var oDocument;
 var oStylesheet;
 if(window.ActiveXObject)
 {
  oDocument = document.XMLDocument;
  oStylesheet = document.XSLDocument;
 }
 else
 {
  oDocument = createDocument();
  oStylesheet = createDocument();
  oDocument.load("");
  var sStylesheet = oDocument.selectSingleNode("processing-instruction('xml-stylesheet')").nodeValue;
  oStylesheet.load(sStylesheet.substring(6, sStylesheet.indexOf(" ") - 1));
 }
 var oRoot = oStylesheet.documentElement;
 oRoot.selectSingleNode("xsl:param[@name = 'sort']").text = document.getElementById("sort").value;
 oRoot.selectSingleNode("xsl:param[@name = 'page']").text = document.getElementById("page").value;
 var oTemplate = oRoot.selectSingleNode("xsl:template[@match = 'rss']");
 if(oTemplate)
 {
  oRoot.removeChild(oTemplate);
 }
 document.body.innerHTML = oDocument.transformNode(oStylesheet);
}]]>
    </script>
   </head>
   <body style="">
    <xsl:apply-templates select="channel"/>
   </body>
  </html>
 </xsl:template>
 <xsl:template match="channel">
  <xsl:apply-templates select="item" mode="page">
   <xsl:sort select="*[name() = $sort]"/>
  </xsl:apply-templates>
  <select id="sort" onchange="refreshXml()">
   <xsl:apply-templates select="item[1]/title | item[1]/description" mode="sort"/>
  </select>
  <select id="page" onchange="refreshXml()">
   <xsl:apply-templates select="item[position() mod $size = 1]" mode="index"/>
  </select>
 </xsl:template>
 <xsl:template match="item" mode="page">
  <xsl:if test="position() &gt; ($page - 1) * $size and position() &lt;= $page * $size">
   <xsl:apply-templates select="."/>
  </xsl:if>
 </xsl:template>
 <xsl:template match="*" mode="sort">
  <option value="{name()}">
   <xsl:if test="name() = $sort">
    <xsl:attribute name="selected">selected</xsl:attribute>
   </xsl:if>
   <xsl:value-of select="name()"/>
  </option>
 </xsl:template>
 <xsl:template match="item" mode="index">
  <option value="{position()}">
   <xsl:if test="position() = $page">
    <xsl:attribute name="selected">selected</xsl:attribute>
   </xsl:if>
   <xsl:value-of select="position()"/>
  </option>
 </xsl:template>
 <xsl:template match="item">
  <a href="{link}">
   <xsl:value-of select="title"/>
  </a>
  <div>
   <xsl:value-of select="description"/>
  </div>
 </xsl:template>
</xsl:stylesheet>
支持排序分页,跨浏览器,但是我以前说过,由于缓存问题,并不推荐Mozilla内核的浏览器是用,只要的还是给大家开阔一下思路。
忘了说了,需要应用我的XMLDOM框架,详情请见http://bbs.xml.org.cn/dispbbs.asp?boardID=11&ID=69284

--  作者:hexun831012
--  发布时间:11/9/2008 12:39:00 PM

--  
申请精华,我就还差1篇了
--  作者:binggo1005
--  发布时间:1/1/2009 10:35:00 PM

--  
ding
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms