xpath 分页
http://bbs.xml.org.cn/dispbbs.asp?BoardID=8&id=45570&replyID=87334&star=1&skin=0
<?xml version="1.0" encoding="utf-8"?>
<!--Copyright© 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() >= 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>
<?xml version="1.0" encoding="utf-8"?>
<!--Copyright© 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() >= 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>