|
在我们的XSLT文件中,使用了两个循环,我们分别进行相应的更改,第一处:显示表头的地方改为<xsl:for-each select="./*[1]/*">,它等同于<xsl:for-each select="客户关系表/客户[1]/*">;第二处循环是显示每行记录,改成<xsl:for-each select="./*">。还有其他的地方需要更改的,请参见后面的完整源代码部分。这样我们就完成了通用的XSLT文件,不管你的XML数据有多少字段,也不管节点名称是什么,我们都无需更改XSLT文件,就可以实现我们的功能了。最终的浏览效果将会象下图所示:
以下是完整的Style.xsl文件的内容: <?xml version="1.0" encoding="gb2312"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://lucky.myrice.com" version="1.0"> <msxsl:script language="VBScript" implements-prefix="user"> <![CDATA[ Function getName(node) getName = node.Item(0).nodeName End Function }> </msxsl:script> <xsl:template match="/"> <xsl:apply-templates select="/*"/> </xsl:template> <xsl:template match="/*"> <table width="100%" border="0" style="font-size:9pt"> <tr> <td align="left"><b>第 <span id="CurrentPage"></span> 页 总 <span id="PageCount"></span> 页 共有 <span id="RecordCount"></span> 条记录</b></td> <td align="right"><b>每页记录数:<input onblur="setRecordsPerPage()" id="RecordsPerPage" style="vertical-align:middle;height:15pt;width:30px"/></b></td> <td align="right"> <span id="Paging"> <input type="button" OnClick="FirstPage()" value="第一页"/> <input type="button" OnClick="previousPage(1)" value="上一页"/> <input type="button" OnClick="nextPage(1)" value="下一页"/> <input type="button" OnClick="LastPage()" value="最末页"/> </span> </td> </tr> </table> <Table WIDTH="100%" BORDER="0" cellpadding="0" cellspacing="1" style="font-size:11pt" bgcolor="#0099ff"> <tr bgcolor="#FF6600" style="cursor: hand;padding:5px"> <xsl:for-each select="./*[1]/*"> <td align="center"> <xsl:attribute name="onclick"> Sort(''<xsl:value-of select="user:getName(.)"/>'') </xsl:attribute> <font color="#EEEEEE"><b><u><xsl:value-of select="user:getName(.)"/></u></b></font> </td> </xsl:for-each> </tr> <xsl:for-each select="./*[position() < 6 and position() > 0]"> <xsl:sort select="./*[1]" order="ascending"/> <tr bgcolor="#FFCCFF"> <xsl:for-each select="./*"> <td> <xsl:value-of select="."/></td> </xsl:for-each> </tr> </xsl:for-each> </Table> </xsl:template> </xsl:stylesheet> 以下是进行输出的Exam.htm文件: <HTML> <Head> <META http=equiv="Content-Type" Content="text/html;charset=gb2312"> <STYLE> body { font-family:宋体; font-size:9pt;} th { font-family:宋体; font-size:11pt; font-weight:bold;} </STYLE> <Script language="vbscript"> Option Explicit Dim intRecordsPerPage ''每个页面显示的记录数 intRecordsPerPage = 6 ''每个页面显示的记录数,默认设定为6 '' 更新显示页面的函数 Function window_onload() '' 显示设定的记录数 Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]" transform() setPageCount() End Function '' 进行XML-XSLT转换,并显示当前记录的一些信息 Function transform() DisplayArea.innerHTML = Data.transformNode(Style.DocumentElement) RecordsPerPage.Value = intRecordsPerPage End Function
共5页: 上一页 [1] [2] 3 [4] [5] 下一页
|