跨浏览器的xslt分页(一)

xml文件(rss2.0)
 
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="template.xsl"?>
<rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>电影</title>
<link>http://localhost:8080/rss/3.xml</link>
<description>电影频道</description>
<image>
<title>添加</title>
<url>http://localhost:8080/rss/images/add.gif</url>
<description>添加</description>
</image>
<item>
<title>土豆视频</title>
<link>http://www.tudou.com</link>
<description>土豆视频</description>
<pubDate>Mon, 17 Dec 2007 16:00:00 GMT</pubDate>
<guid>http://www.tudou.com</guid>
<dc:date>2007-12-17T16:00:00Z</dc:date>
</item>
<item>
<title>六间房</title>
<link>http://www.6rooms.com</link>
<description>六间房电影</description>
<pubDate>Tue, 01 Jan 2008 16:00:00 GMT</pubDate>
<guid>http://www.6rooms.com</guid>
<dc:date>2008-01-01T16:00:00Z</dc:date>
</item>
<item>
<title>tom电影频道</title>
<link>http://ent.tom.com/movie/</link>
<description>tom电影</description>
<pubDate>Tue, 01 Jan 2008 16:00:00 GMT</pubDate>
<guid>http://ent.tom.com/movie/</guid>
<dc:date>2008-01-01T16:00:00Z</dc:date>
</item>
<item>
<title>迅雷电影</title>
<link>http://www.xunlei.com</link>
<description>迅雷电影</description>
<pubDate>Tue, 01 Jan 2008 16:00:00 GMT</pubDate>
<guid>http://www.xunlei.com</guid>
<dc:date>2008-01-01T16:00:00Z</dc:date>
</item>
<item>
<title>网易电影</title>
<link>http://ent.163.com/movie/</link>
<description>网易电影</description>
<pubDate>Tue, 01 Jan 2008 16:00:00 GMT</pubDate>
<guid>http://ent.163.com/movie/</guid>
<dc:date>2008-01-01T16:00:00Z</dc:date>
</item>
</channel>
</rss>


xsl文件:

<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--Declare Current Page-->
<xsl:param name="current">1</xsl:param>
<!--Declare Page Size-->
<xsl:param name="page">2</xsl:param>
<!--Declare xmlDocument address-->
<xsl:param name="ad">3.xml</xsl:param>


<xsl:template match="/">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title><xsl:value-of select="rss/channel/title"/></title>
<script type="text/javascript">
function paging(page,ad){
var xmlDocument;
var xslDocument;


if (window.ActiveXObject){
xslDocument=new ActiveXObject("Microsoft.XMLDOM");
xslDocument.async=false;

xmlDocument=new ActiveXObject("Microsoft.XMLDOM");
xmlDocument.async=false;

xslDocument.load("template.xsl");
xmlDocument.load(ad);

xslDocument.selectNodes("xsl:stylesheet/xsl:template[@match='/']").removeAll();
xslDocument.selectSingleNode("xsl:stylesheet/xsl:param[@name='current']").text=page;

document.body.innerHTML=xmlDocument.transformNode(xslDocument);

}else{ // code for Mozilla, Firefox, Opera, etc.
xslDocument=document.implementation.createDocument("","",null);
xslDocument.async = false;

xmlDocument=document.implementation.createDocument("","",null);
xmlDocument.async=false;

xslDocument.load("template.xsl");
xmlDocument.load(ad);

var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xslDocument);
xsltProcessor.setParameter(null,"current",page);
var result = xsltProcessor.transformToDocument(xmlDocument);
var xmls = new XMLSerializer();
document.body.innerHTML = xmls.serializeToString(result);
}
}
</script>
</HEAD>
<body topmargin="0" leftmargin="0" bgcolor="#47A3AC" background="http://61.158.218.76/eums/generator/img/cncbg06040415593.jpg">
<xsl:apply-templates/>
</body>
</HTML>
</xsl:template>

<xsl:template match="rss" name="show1">
<xsl:apply-templates select="item[position() >= ($current - 1) * $page and position() <= $current * $page]"/>
<xsl:call-template name="page"/>
</xsl:template>

<xsl:template match="rss" name="show">
<table border="0" cellspacing="0" cellpadding="0" style="position: absolute; width: 204px; height: 33px; left: 72px; top:13px">
<tr>
<td align="left"><span style="text-decoration:none"><font color="#FAFAFA"><strong>当前栏目:<xsl:value-of select="channel/title"/></strong></font></span></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" style="position: absolute; width: 600px; height: 313px; left: 25px; top:55px">
<tr>
<td>
<font color="#FAFAFA"><span style="text-decoration: none"><strong>
Feed地址:<xsl:value-of select="channel/link"/></strong></span></font>
</td>
</tr>
<tr>
<td>
<font color="#FAFAFA"><span style="text-decoration: none"><strong>当前Feed内容: </strong></span></font>
</td>
</tr>
<xsl:for-each select="channel/item[position() > ($current - 1) * $page and position() <= $current * $page]">
<tr>
<td>
<table width="300" height="30" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="left" valign="middle" height="29">
<a>
<xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
<font color="#FAFAFA" size="2"><span style="text-decoration: none"><strong><xsl:value-of select="title"/> </strong></span></font>
</a>
</td>
</tr>
<tr>
<td align="left" valign="middle" height="29">
<font size="2" color="#FAFAFA" face="Arial"><xsl:value-of select="description"/></font>
</td>
</tr>
<tr>
<td align="left" valign="middle" height="29">
<font size="2" color="#FAFAFA" face="Arial"><xsl:value-of select="pubDate"/></font>
</td>
</tr>
</table>
</td>
<td>
<table width="300" height="30" border="0" cellspacing="1" cellpadding="0">
<tr>
<xsl:for-each select="/rss/channel/image">
<td align="left" valign="middle" height="29">

<img>
<xsl:attribute name="src"><xsl:value-of select="/rss/channel/image/url"/></xsl:attribute>
</img>
</td>
</xsl:for-each>
</tr>
</table>
</td>
</tr>

</xsl:for-each>
<tr>
<td>
<xsl:call-template name="show1"/>
</td>
</tr>
</table>
</xsl:template>

<xsl:template name="page">


<xsl:for-each select="/rss/channel/item[position() mod $page = 1]">
<a href="javascript:paging({position()},'{$ad}')">
<font color="#FAFAFA" size="3"><span style="text-decoration: none"><strong>
<xsl:value-of select="position()"/>
</strong></span></font>
</a><xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值