小弟刚接触xsl,找到了一个xsl分页的例子,但是不知道怎样改xsl才是我的xml的效果,请各位朋友帮忙看看,谢谢!
我的xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<rss version= "2.0 ">
<channel>
<generator> NFE/1.0 </generator>
<link> http://news.google.com/news?q=%E5%A5%A5%E8%BF%90%E5%9C%A3%E7%81%AB&hl=zh-CN&lr=&nxpt=20.946262443952854650275&ie=UTF-8&oe=UTF-8&um=1&tab=wn </link>
<description> 奥运圣火 - Google 资讯 </description>
<language> zh-CN </language>
<webMaster> news-feedback@google.com </webMaster>
<copyright> &copy;2007 Google </copyright>
<pubDate> Fri, 27 Apr 2007 06:52:36 GMT </pubDate>
<lastBuildDate> Fri, 27 Apr 2007 06:52:36 GMT </lastBuildDate>
<image>
<title> 奥运圣火 - Google 资讯 </title>
<url> http://news.google.com/intl/zh-CN_cn/images/news_res.gif </url>
<link> http://news.google.com/ </link>
</image>
<item>
<title> 北京奥运圣火明年5月登顶珠峰 - 新浪网 </title>
<link> http://news.google.com/news/url?sa=T&ct=cn/0-0&fd=R&url=http://news.sina.com.cn/o/2007-04-27/124911728474s.shtml&cid=1112826555&ei=s50xRviLNaGMqQP3_YDzBQ </link>
<guid isPermaLink= "false "> tag:news.google.com,2005:cluster=425462bb </guid>
<pubDate> Fri, 27 Apr 2007 04:52:00 GMT </pubDate>
<description> <br><table border=0 width= valign=top cellpadding=2 cellspacing=7><tr><td width=80 align=center valign=top><a href= "http://news.google.com/news/url?sa=T&ct=cn/0i-0&fd=R&url=http://2008.sports.tom.com/2007-04-26/0C4P/46353773.html&cid=1112826555&ei=s50xRviLNaGMqQP3_YDzBQ "><img src=http://news.google.com/news?imgefp=4-6pVeIgCcMJ&imgurl=2008.sports.tom.com/uimg/2007/4/26/wuzhongyan/1177591953343_43216.jpg width=79 height=52 alt= " " border=1><br><font size=-2>TOM</font></a></td><td valign=top class=j><a href= "http://news.google.com/news/url?sa=T&ct=cn/0-0&fd=R&url=http://news.sina.com.cn/o/2007-04-27/124911728474s.shtml&cid=1112826555&ei=s50xRviLNaGMqQP3_YDzBQ " target=_blank>北京<font color=#CC0033>奥运圣火</font>明年5月登顶珠峰</a><br><font size=-1><font color=#6f6f6f>新浪网&nbsp;-</font> <nobr>2小时前</nobr></font><br><font size=-1>2008年8月8日,“祥云照耀”下,经过2万多名火炬手,13.7万公里传递的<font color=#CC0033>奥运圣火</font>,将点燃北京奥运会主体育场上的主火炬,掀开奥林匹克光辉的新篇章,此次圣火还将分出一支分火种登上西藏珠峰展示。 2005年12月6日,北京奥组委面向全球发出公开征集火炬设计方案的邀请,北京奥组委收到有效作品388件。2007年1月,经国际奥委会批准,“祥云”设计 <b>...</b></font><br><font size=-1><a href= "http://news.google.com/news/url?sa=T&ct=cn/0-1&fd=R&url=http://sports.zaobao.com/pages9/others070427.html&cid=1112826555&ei=s50xRviLNaGMqQP3_YDzBQ " target=_blank>北京<font color=#CC0033>奥运圣火</font>传递路线公布</a> <font size=-1 color=#6f6f6f><nobr>联合早报</nobr></font></font><br><font size=-1><a href= "http://news.google.com/news/url?sa=T&ct=cn/0-2&fd=R&url=http://www.nanfangdaily.com.cn/southnews/dd/nfrb/A02/200704270103.asp&cid=1112826555&ei=s50xRviLNaGMqQP3_YDzBQ " target=_blank>44年来<font color=#CC0033>奥运圣火</font>将首次到台湾</a> <font size=-1 color=#6f6f6f><nobr>南方日报</nobr></font></font><br><font size=-1><a href= "http://news.google.com/news/url?sa=T&ct=cn/0-3&fd=R&url=http://news.sina.com.cn/o/2007-04-27/123111728436s.shtml&cid=1112826555&ei=s50xRviLNaGMqQP3_YDzBQ " target=_blank>北京<font color=#CC0033>奥运圣火</font>明年4月起全球传递明年7月14日至16日在我省传递</a> <font size=-1 color=#6f6f6f><nobr>新浪网</nobr></font></font><br><font size=-1 class=p><a href= "http://news.google.com/news/url?sa=T&ct=cn/0-4&fd=R&url=http://chinanews.sina.com/sports/2007/0426/21051963959.html&cid=1112826555&ei=s50xRviLNaGMqQP3_YDzBQ " target=_blank><nobr>新浪北美</nobr></a>&nbsp;- <a href= "http://news.google.com/news/url?sa=T&ct=cn/0-5&fd=R&url=http://www.bj.xinhuanet.com/bjpd_2008/2007-04/27/content_9909053.htm&cid=1112826555&ei=s50xRviLNaGMqQP3_YDzBQ " target=_blank><nobr>新华网北京频道</nobr></a></font><br/><font class=p size=-1><a class=p href=http://news.google.com/news?hl=zh-CN&lr=&nxpt=20.946262443952854650275&ie=UTF-8&oe=UTF-8&tab=wn&ncl=1112826555><nobr>所有1,456条相关资讯</nobr></a></font></table> </description>
</item>
</channel>
</rss>
我的xsl:
<?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 " omit-xml-declaration= "yes "/>
<xsl:template match= "/rss/channel ">
<b>
<xsl:value-of select= "title " disable-output-escaping= "yes "/>
</b>
<xsl:for-each select= "item ">
<li>
<a>
<xsl:attribute name= "href ">
<xsl:value-of select= "link " disable-output-escaping= "yes "/>
</xsl:attribute>
<xsl:attribute name= "target "> _blank </xsl:attribute>
<xsl:value-of select= "title " disable-output-escaping= "yes "/>
</a>
( <xsl:value-of select= "pubDate "/> )
</li>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我想要的分页效果是http://www.caisong.com/read.php/414.htm 里的page.xsl效果
请问怎样把我的xsl改成带分页http://www.caisong.com/read.php/414.htm 里的page.xsl效果,谢谢!
[解决办法]
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="page.xsl" ?>
<list>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
<item>13</item>
</list>[/QUOTE]
page.xsl
[QUOTE]<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="size" select="4"/>
<xsl:template match="list">
<html>
<script>
<![CDATA[
function nextPage(num){
document.getElementById("content"+num).style.display="";
num--;
document.getElementById("content"+num).style.display="none";
}
function prevPage(num){
document.getElementById("content"+num).style.display="";
num++;
document.getElementById("content"+num).style.display="none";
}
function onInitialize(){
var i = 1;
document.getElementById("content"+i).style.display = "";
}
]]>
</script>
<body onload="onInitialize()">
<xsl:apply-templates select="item[position() mod $size = 1]">
<xsl:with-param name="pages" select="ceiling(count(item) div $size)"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="item">
<xsl:param name="pages"/>
<xsl:variable name="page" select="position()"/>
<div id='content{$page}' style="display:'none'" title="content{$page}">
<xsl:for-each select="self::item | following-sibling::item[position() < $size]">
<div><xsl:value-of select="."/></div>
</xsl:for-each>
<div id="navBar">
<xsl:choose>
<xsl:when test="$page = 1">
第<xsl:value-of select="$page" />页---
<a href="#{$page + 1}" onclick="nextPage({$page + 1})">下一页</a>---
共有<xsl:value-of select="$pages" />页---
</xsl:when>
<xsl:when test="$page = $pages">
第<xsl:value-of select="$page" />页---
<a href="#{$page - 1}" onclick="prevPage({$page - 1})">上一页</a>---
共有<xsl:value-of select="$pages" />页---
</xsl:when>
<xsl:otherwise>
第<xsl:value-of select="$page" />页---
<a href="#{$page - 1}" onclick="prevPage({$page - 1})">上一页</a>---
<a href="#{$page + 1}" onclick="nextPage({$page + 1})">下一页</a>---
共有<xsl:value-of select="$pages" />页---
</xsl:otherwise>
</xsl:choose>
</div>
</div>
</xsl:template>
</xsl:stylesheet>
弱化了对js的依赖,还不错