XML之动态排序的详细信息
有2个文件:Page.xml和Page.xslPage.xml:
<?xmlversion="1.0"encoding="gb2312"?>
<?xml-stylesheettype="text/xsl"href="Page.xsl"?>
<BlueIdea>
<team>
<blue_ID>1</blue_ID>
<blue_name>车仔</blue_name>
<blue_text>一个简单的排序</blue_text>
<blue_time>2002-1-1117:35:33</blue_time>
<blue_class>XML专题</blue_class>
</team>
<team>
<blue_ID>2</blue_ID>
<blue_name>flyingbird</blue_name>
<blue_text>嫁给你,是要你疼的</blue_text>
<blue_time>2001-09-0612:45:51</blue_time>
<blue_class>灌水精华</blue_class>
</team>
<team>
<blue_ID>3</blue_ID>
<blue_name>苛子</blue_name>
<blue_text>正则表达式在UBB论坛中的应用</blue_text>
<blue_time>2001-11-2321:02:16</blue_time>
<blue_class>Web编程精华</blue_class>
</team>
<team>
<blue_ID>4</blue_ID>
<blue_name>太乙郎</blue_name>
<blue_text>年末经典分舵聚会完全手册v0.1</blue_text>
<blue_time>2000-12-0810:22:48</blue_time>
<blue_class>论坛灌水区</blue_class>
</team>
<team>
<blue_ID>5</blue_ID>
<blue_name>mmkk</blue_name>
<blue_text>Asp错误信息总汇</blue_text>
<blue_time>2001-10-1316:39:05</blue_time>
<blue_class>javascript脚本</blue_class>
</team>
</BlueIdea>
<?xml-stylesheettype="text/xsl"href="Page.xsl"?>
<BlueIdea>
<team>
<blue_ID>1</blue_ID>
<blue_name>车仔</blue_name>
<blue_text>一个简单的排序</blue_text>
<blue_time>2002-1-1117:35:33</blue_time>
<blue_class>XML专题</blue_class>
</team>
<team>
<blue_ID>2</blue_ID>
<blue_name>flyingbird</blue_name>
<blue_text>嫁给你,是要你疼的</blue_text>
<blue_time>2001-09-0612:45:51</blue_time>
<blue_class>灌水精华</blue_class>
</team>
<team>
<blue_ID>3</blue_ID>
<blue_name>苛子</blue_name>
<blue_text>正则表达式在UBB论坛中的应用</blue_text>
<blue_time>2001-11-2321:02:16</blue_time>
<blue_class>Web编程精华</blue_class>
</team>
<team>
<blue_ID>4</blue_ID>
<blue_name>太乙郎</blue_name>
<blue_text>年末经典分舵聚会完全手册v0.1</blue_text>
<blue_time>2000-12-0810:22:48</blue_time>
<blue_class>论坛灌水区</blue_class>
</team>
<team>
<blue_ID>5</blue_ID>
<blue_name>mmkk</blue_name>
<blue_text>Asp错误信息总汇</blue_text>
<blue_time>2001-10-1316:39:05</blue_time>
<blue_class>javascript脚本</blue_class>
</team>
</BlueIdea>
Page.xsl:
<?xmlversion="1.0"encoding="gb2312"?>
<xsl:stylesheetxmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:templatematch="/">
<html>
<head>
<title>
车仔手札--XML卷之(3):动态分页
</title>
<style>
body,BlueIdea,team,blue_ID,blue_name,blue_text,blue_time,blue_class{font:12px"宋体","Arial","TimesNewRoman";}
table{font-size:12px;border:0pxdouble;border-color:#99CC99#99CC99#CCCCCC#CCCCCC;cellpadding:3;cellspacing:3;bgcolor:#eeeeee;text-decoration:blink}
.keybutton{cursor:hand;font-size:12px;color:#003300;background:#ffffff;border:0pxsolid;}
</style>
<script>
<xsl:comment>
<![CDATA[
varsearch;
varOnePageNum=2;
varPageNum=1;
varXMLPageNum=1;
functionwindow.onload()
{
stylesheet=document.XSLDocument;
source=document.XMLDocument;
nodes=source.documentElement.childNodes;
len=nodes.length;
for(i=1;i<=(len/OnePageNum);i++);
XMLPageNum=i;
}
functionpages(Num)
{
varfirstNum=0;
varlastNume=0;
if(Num=="first"){PageNum=1;}
if(Num=="previous"){if(PageNum>1)PageNum-=1;}
if(Num=="next"){if(PageNum<XMLPageNum)PageNum+=1;}
if(Num=="last"){PageNum=XMLPageNum;}
sortField=document.XSLDocument.selectSingleNode("//@expr");
firstNum=OnePageNum*(PageNum-1)+1;
lastNum=OnePageNum*(PageNum-1)+OnePageNum;
text="childnumber(this)>="+firstNum+"&childnumber(this)<="+lastNum;
sortField.value=text;
Layer1.innerHTML=source.documentElement.transformNode(stylesheet);
}
]]>
</xsl:comment>
</script>
</head>
<body>
<tablealign="center"width="600">
<tr>
<td>
<buttonid="cmdfirstPage"class="keybutton"onclick="pages('first');">首页</button>
<buttonid="cmdpreviousPage"class="keybutton"onclick="pages('previous');">上一页</button>
<buttonid="cmdnextPage"class="keybutton"onclick="pages('next');">下一页</button>
<buttonid="cmdlastPage"class="keybutton"onclick="pages('last');">尾页</button>
</td>
</tr>
</table>
<br/>
<divid="Layer1"name="Layer1"><xsl:apply-templatesselect="BlueIdea"/></div>
</body>
</html>
</xsl:template>
<xsl:templatematch="BlueIdea">
<tablewidth="600"border="1"align="center"cellpadding="1"cellspacing="1"bordercolordark="#ffffff"bordercolorlight="#ADAAAD">
<trbgcolor="#FFCC99"align="center">
<td>编号</td>
<td>姓名</td>
<td>主题</td>
<td>发表时间</td>
<td>归类</td>
</tr>
<xsl:apply-templatesselect="team"order-by="blue_ID"/>
</table>
</xsl:template>
<xsl:templatematch="team">
<xsl:ifexpr="childnumber(this)>=1&childnumber(this)<=2">
<tralign="center">
<xsl:apply-templatesselect="blue_ID"/>
<xsl:apply-templatesselect="blue_name"/>
<xsl:apply-templatesselect="blue_text"/>
<xsl:apply-templatesselect="blue_time"/>
<xsl:apply-templatesselect="blue_class"/>
</tr>
</xsl:if>
</xsl:template>
<xsl:templatematch="blue_ID">
<tdbgcolor="#eeeeee">
<xsl:value-of/>
</td>
</xsl:template>
<xsl:templatematch="blue_name">
<td><xsl:value-of/></td>
</xsl:template>
<xsl:templatematch="blue_text">
<td>
<xsl:value-of/>
</td>
</xsl:template>
<xsl:templatematch="blue_time">
<td>
<xsl:value-of/>
</td>
</xsl:template>
<xsl:templatematch="blue_class">
<td>
<xsl:value-of/>
</td>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheetxmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:templatematch="/">
<html>
<head>
<title>
车仔手札--XML卷之(3):动态分页
</title>
<style>
body,BlueIdea,team,blue_ID,blue_name,blue_text,blue_time,blue_class{font:12px"宋体","Arial","TimesNewRoman";}
table{font-size:12px;border:0pxdouble;border-color:#99CC99#99CC99#CCCCCC#CCCCCC;cellpadding:3;cellspacing:3;bgcolor:#eeeeee;text-decoration:blink}
.keybutton{cursor:hand;font-size:12px;color:#003300;background:#ffffff;border:0pxsolid;}
</style>
<script>
<xsl:comment>
<![CDATA[
varsearch;
varOnePageNum=2;
varPageNum=1;
varXMLPageNum=1;
functionwindow.onload()
{
stylesheet=document.XSLDocument;
source=document.XMLDocument;
nodes=source.documentElement.childNodes;
len=nodes.length;
for(i=1;i<=(len/OnePageNum);i++);
XMLPageNum=i;
}
functionpages(Num)
{
varfirstNum=0;
varlastNume=0;
if(Num=="first"){PageNum=1;}
if(Num=="previous"){if(PageNum>1)PageNum-=1;}
if(Num=="next"){if(PageNum<XMLPageNum)PageNum+=1;}
if(Num=="last"){PageNum=XMLPageNum;}
sortField=document.XSLDocument.selectSingleNode("//@expr");
firstNum=OnePageNum*(PageNum-1)+1;
lastNum=OnePageNum*(PageNum-1)+OnePageNum;
text="childnumber(this)>="+firstNum+"&childnumber(this)<="+lastNum;
sortField.value=text;
Layer1.innerHTML=source.documentElement.transformNode(stylesheet);
}
]]>
</xsl:comment>
</script>
</head>
<body>
<tablealign="center"width="600">
<tr>
<td>
<buttonid="cmdfirstPage"class="keybutton"onclick="pages('first');">首页</button>
<buttonid="cmdpreviousPage"class="keybutton"onclick="pages('previous');">上一页</button>
<buttonid="cmdnextPage"class="keybutton"onclick="pages('next');">下一页</button>
<buttonid="cmdlastPage"class="keybutton"onclick="pages('last');">尾页</button>
</td>
</tr>
</table>
<br/>
<divid="Layer1"name="Layer1"><xsl:apply-templatesselect="BlueIdea"/></div>
</body>
</html>
</xsl:template>
<xsl:templatematch="BlueIdea">
<tablewidth="600"border="1"align="center"cellpadding="1"cellspacing="1"bordercolordark="#ffffff"bordercolorlight="#ADAAAD">
<trbgcolor="#FFCC99"align="center">
<td>编号</td>
<td>姓名</td>
<td>主题</td>
<td>发表时间</td>
<td>归类</td>
</tr>
<xsl:apply-templatesselect="team"order-by="blue_ID"/>
</table>
</xsl:template>
<xsl:templatematch="team">
<xsl:ifexpr="childnumber(this)>=1&childnumber(this)<=2">
<tralign="center">
<xsl:apply-templatesselect="blue_ID"/>
<xsl:apply-templatesselect="blue_name"/>
<xsl:apply-templatesselect="blue_text"/>
<xsl:apply-templatesselect="blue_time"/>
<xsl:apply-templatesselect="blue_class"/>
</tr>
</xsl:if>
</xsl:template>
<xsl:templatematch="blue_ID">
<tdbgcolor="#eeeeee">
<xsl:value-of/>
</td>
</xsl:template>
<xsl:templatematch="blue_name">
<td><xsl:value-of/></td>
</xsl:template>
<xsl:templatematch="blue_text">
<td>
<xsl:value-of/>
</td>
</xsl:template>
<xsl:templatematch="blue_time">
<td>
<xsl:value-of/>
</td>
</xsl:template>
<xsl:templatematch="blue_class">
<td>
<xsl:value-of/>
</td>
</xsl:template>
</xsl:stylesheet>
本文地址:http://www.45fan.com/dnjc/70218.html