在51JS的处女贴--XSL分页条template
spliter.xsl<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!--当前页码-->
<xsl:param name="page"><xsl:value-of select="//page"/></xsl:param>
<!--基础URL-->
<xsl:param name="url">/xxx.aspx?p=</xsl:param>
<!--示例-->
<xsl:template match="/">
<div>
<!--调用分页条生成模板-->
<xsl:call-template name="pager">
<!--参数:总页数-->
<xsl:with-param name="tp">
<!--计算总页数,count节点表示总的记录数,div 20表示每页20条记录-->
<xsl:value-of select="round(number(//count) div 20+0.49)"/>
</xsl:with-param>
</xsl:call-template>
</div>
</xsl:template>
<xsl:template name="pager">
<!--参数:总页数-->
<xsl:param name="tp"/>
<!--如果总页熟大于1则开始生成分页链节-->
<xsl:if test="$tp>1">
<!--如果当前页不是第一页则生成上一页的链接-->
<xsl:if test="($page)>1">
<a target="_self">
<xsl:attribute name="href">
<xsl:value-of select="$url" /><xsl:value-of select="number($page)-1" />
</xsl:attribute>
上一页
</a>
</xsl:if>
<!--调用循环生成中间的页码链接-->
<xsl:call-template name="loop">
<!--参数:开始页码-->
<xsl:with-param name="start">
<xsl:choose>
<!--如果总页数大于10并且当前页码大于5则开始计算起始页码,否则起始页码为1-->
<xsl:when test="$tp>10 and $page>5">
<xsl:choose>
<!--如果总页数大于当前页加5则起始页码为当前页减5-->
<xsl:when test="$tp>$page+5">
<xsl:value-of select="number($page)-5"/>
</xsl:when>
<!--否则起始页码为总页数减10-->
<xsl:otherwise><xsl:value-of select="number($tp)-10"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<!--参数:结束页码-->
<xsl:with-param name="end">
<xsl:choose>
<!--如果总页数大于10则开始结算结束页码,否则结束页码为总页数-->
<xsl:when test="$tp>10">
<xsl:choose>
<!--如果总页数大于当前页码加5-->
<xsl:when test="$tp>$page+5">
<xsl:choose>
<!--如果当前页码大于5,则结果页码为当前页码加5-->
<xsl:when test="$page>5">
<xsl:value-of select="number($page)+5"/>
</xsl:when>
<!--否则结果页码为10-->
<xsl:otherwise>10</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!--否则结果页码为总页数-->
<xsl:otherwise><xsl:value-of select="$tp"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$tp"/></xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<!--如果当前页不是最后一页则生成下一页的链接-->
<xsl:if test="$tp>number($page)">
<a target="_self">
<xsl:attribute name="href">
<xsl:value-of select="$url" /><xsl:value-of select="number($page)+1" />
</xsl:attribute>
下一页
</a>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="loop">
<!--参数:开始页码-->
<xsl:param name="start"/>
<!--参数:结束页码-->
<xsl:param name="end"/>
<!--如果结束页码大于开始页码则继续处理下一个链接-->
<xsl:if test="$end>=$start">
<xsl:choose>
<!--如果是当前页则只显示页码不创建链接-->
<xsl:when test="$start=$page">
<span>
<xsl:value-of select="$start"/>
</span>
</xsl:when>
<!--创建链接页码-->
<xsl:otherwise>
<a target="_self">
<xsl:attribute name="href">
<xsl:value-of select="$url" /><xsl:value-of select="$start" />
</xsl:attribute>
[<xsl:value-of select="$start" />]
</a>
</xsl:otherwise>
</xsl:choose>
<!--继续生成下一个链接-->
<xsl:call-template name="loop">
<!--开始页码加1后传入下一个调用-->
<xsl:with-param name="start">
<xsl:value-of select="number($start)+1"/>
</xsl:with-param>
<!--结束页码直接传入下一个调用-->
<xsl:with-param name="end">
<xsl:value-of select="$end"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
spliter.xml
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="spliter.xsl"?>
<root>
<page>3</page>
<count>5864</count>
</root>
[ 本帖最后由 silverdrag 于 2007-8-25 14:30 编辑 ] 不错…… 支持一下原创.
不过应该可以进一步精减?
URL 和 PageCount 等配置信息似乎不应该写在XSL里. 否则一但需要在不同地方使用不同配置就得写不同的 XSL 文件. 赞
页:
[1]