xml+xsl分页 不错!
http://blog.csdn.net/pangpangde/archive/2006/07/07/890258.aspx
page.xml
<?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>
page.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="size" select="6"/>
<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>
------------------------------------
Escape Characters
转义符
Illegal XML characters have to be replaced by entity references.
非法的XML字符必须由实体参数替代。
If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. You cannot write something like this:
如果你在一个XML元素中放置一个 "<" 字符,就会产生错误,因为解析器会误认为它是新元素的开始。你不可以写成下面这样:
<message>if salary < 1000 then</message> |
To avoid this, you have to replace the "<" character with an entity reference, like this:
为了避免这种情况的发生,你必须使用一个实体参数来替换 "<" ,如下所示:
<message>if salary < 1000 then</message> |
There are 5 predefined entity references in XML:
在XML里,包含5个预定义的实体参数:
< | < | less than[小于] |
> | > | greater than[大于] |
& | & | ampersand [和] |
' | ' | apostrophe[省略号] |
" | " | quotation mark[引号] |
注意: 只有字符"<" 和 "&" 在XML里是严格意义上非法的。省略符,引号和更高级的符号是合法的,用"<" 和 "&"代替它们是更为简便的方法。
CDATA
Everything inside a CDATA section is ignored by the parser.
在CDATA片断内的一切内容都会被解析器忽略。
If your text contains a lot of "<" or "&" characters - as program code often does - the XML element can be defined as a CDATA section.
如果你的文本中包含大量的 "<" 或 "&" 字符——就象程序码中经常的那样——XML元素可以被定义为一个CDATA部分。
A CDATA section starts with "<![CDATA[" and ends with "]]>":
一个CDATA片断由 "<![CDATA[" 开始,由 "]]>" 结束:
<script> |
In the example above, everything inside the CDATA section is ignored by the parser.
在上述案例中,CDATA片断中的所有内容都被解析器忽略了。
Notes on CDATA sections:
CDATA片断的注意事项:
A CDATA section cannot contain the string "]]>", therefore, nested CDATA sections are not allowed.
CDATA片断不能包含字符串 "]]>",因此,嵌套CDATA片断是不允许的。
Also make sure there are no spaces or line breaks inside the "]]>" string.
同时还要注意:在 "]]>" 字符串内不应该包含空格或换行键。