hexun831012的XSL分页
2007/5/4 11:57:23
阅读全文(3731) | 回复(2) | 编辑 | 精华
引自:http://bbs.xml.org.cn/dispbbs.asp?boardID=8&ID=45570 以RSS为例<?xml version="1.0" encoding="utf-8"?><!--Copyright(C) 2003-2007 Hexsoft.org, All Right Reserved.--><xsl:stylesheet version="1.0" xmlns:xsl="' target=_blank>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="' target=_blank>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() >= ($current - 1) * $page and position() <= $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> 更新:支持firefox<?xml version="1.0" encoding="utf-8"?><!--Copyright© 2003-2007 Hexsoft.org, All Right Reserved.--><xsl:stylesheet version="1.0" xmlns:xsl="' target=_blank>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="' target=_blank>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() >= 10 * ($page - 1) and position() <= 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>
Posted by Qr on 2007/5/4 11:57:23
回复:hexun831012的XSL分页
2007/7/18 11:21:50
个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
QR无处不在,呵呵 以下为blog主人的回复: 无处不在你在什么地方见到偶了偶尔论坛,偶尔博客罢了
hexun831012(游客)
Posted by hexun831012(游客) on 2007/7/18 11:21:50
回复:hexun831012的XSL分页
2007/6/27 15:42:03
个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
为什么我的帖子会在这?? 以下为blog主人的回复: 好贴,不收藏觉得可惜!偶也没有修改版权啊,还帮你推广咧
hexun831012(游客)
Posted by hexun831012(游客) on 2007/6/27 15:42:03
发表评论: |