在51JS的处女贴--XSL分页条template
时间:2007-08-25
来源:互联网
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>
提示:您可以先修改部分代码再运行
[[i] 本帖最后由 silverdrag 于 2007-8-25 14:30 编辑 [/i]]
<?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>
提示:您可以先修改部分代码再运行
[[i] 本帖最后由 silverdrag 于 2007-8-25 14:30 编辑 [/i]]
作者: silverdrag 发布时间: 2007-08-25
不错…… 支持一下原创.
不过应该可以进一步精减?
URL 和 PageCount 等配置信息似乎不应该写在XSL里. 否则一但需要在不同地方使用不同配置就得写不同的 XSL 文件.
不过应该可以进一步精减?
URL 和 PageCount 等配置信息似乎不应该写在XSL里. 否则一但需要在不同地方使用不同配置就得写不同的 XSL 文件.
作者: ※潇洒※ 发布时间: 2007-09-09
赞
作者: solidluck 发布时间: 2009-12-22
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28