SoFunction
Updated on 2025-04-08

XML creates sortable and paging data display pages



    
The following is the contents of the complete file:

   <?xml version="1.0" encoding="gb2312"?> 
   <xsl:stylesheet xmlns:xsl="http:///1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="" version="1.0"> 
   <msxsl:script language="VBScript" implements-prefix="user"> 
   <![CDATA[ 
   Function getName(node) 
   getName = (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>Page <span ></span> Total <span ></span> page    There are a total of <span ></span>  records</b></td>
<td align="right"><b>Number of records per page: <input onblur="setRecordsPerPage()"  style="vertical-align:middle;height:15pt;width:30px"/></b></td>
   <td align="right"> 
   <span > 
<input type="button" OnClick="FirstPage()" value="FirstPage"/>
<input type="button" OnClick="previousPage(1)" value="Previous Page"/>
<input type="button" OnClick="nextPage(1)" value="NextPage"/>
<input type="button" OnClick="LastPage()" value="last page"/>
   </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> 
The following are the output files:
   <HTML> 
   <Head> 
   <META http=equiv="Content-Type" Content="text/html;charset=gb2312"> 
   <STYLE> 
body { font-family:An An; font-size:9pt;}
th { font-family:An An; font-size:11pt; font-weight:bold;}
   </STYLE> 
   <Script language="vbscript"> 
   Option Explicit 

Dim intRecordsPerPage ''Number of records displayed on each page
intRecordsPerPage= 6 ''The number of records displayed on each page is set to 6 by default

'' Update the function that displays the page
   Function window_onload() 

'' Display the set number of records
   ("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]" 
   transform() 
   setPageCount() 

   End Function 

'' Perform XML-XSLT conversion and display some information of the current record.
   Function transform() 

    = () 
    = intRecordsPerPage 

   End Function 

'' Reconvert XML and display a status information
   Function redisplay(intPage) 

   Dim strDisplay 
   Dim intPageCount 
   Dim intRecordCount 

''Save status information
   intPageCount =  
   intRecordCount =  
   transform() 
'Show status information
    = intPageCount 
    = intRecordCount 
    = intPage 

   End Function 

'' Reorder and display
   Function Sort(strField) 

   Dim sortField 
   Dim sortOrderAttribute 
''Get the sorted attribute value
   Set sortField = ("//xsl:sort/@select") 
   Set sortOrderAttribute = ("//xsl:sort/@order") 

''Change the sorting method
   If  = strField Or  = "./*[0]" Then 
   If  = "descending" Then 
    = "ascending" 
   Else 
    = "descending" 
   End If 
   Else 
    = strField 
    = "ascending" 
   End If 

   Set sortField = Nothing 
   Set sortOrderAttribute = Nothing 

   redisplay () 

   End Function 

''Reset the number of records per page
   Function setRecordsPerPage() 

   If IsNumeric() Then 
   intRecordsPerPage = CInt() 
   window_onload 
   End If 

   End Function 

'' Display page count information
   Function setPageCount() 

   Dim intTotalRecords 

    = getNumberOfPages(intTotalRecords) 
    = intTotalRecords 
    = 1 

   End Function 

''Calculate the total number of pages and total records
   Function getNumberOfPages(intTotalRecords) 

   Dim intPages 

   intTotalRecords = ("/*/*").length 
   intPages = intTotalRecords / intRecordsPerPage 
   If InStr(intPages, ".") > 0 Then 
   intPages = CInt(Left(intPages, InStr(intPages, "."))) + 1 
   End If 

   getNumberOfPages = intPages 

   End Function 

'' The processing of "next page"
   Function nextPage(intPage) 

   Dim strDisplay 
   Dim strDateRange 

   If CInt(CStr(intPage) * intRecordsPerPage) < ("/*/*").length Then 
   intPage = CInt(intPage) + 1 
   ("//@OnClick")(1).Value = "previousPage(" & intPage & ")" 
   ("//@OnClick")(2).Value = "nextPage(" & intPage & ")" 
   ("//xsl:for-each/@select")(1).Value = "./*[position() <= " & (CStr(intPage) * intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]" 
   redisplay (intPage) 
   End If 

   End Function 

''  Processing "Previous Page"
   Function previousPage(intPage) 

   Dim strDisplay 
   Dim strDateRange 

   If intPage > 1 Then 
   intPage = CInt(intPage) - 1 
   ("//@OnClick")(1).Value = "previousPage(" & intPage & ")" 
   ("//@OnClick")(2).Value = "nextPage(" & intPage & ")" 
   ("//xsl:for-each/@select")(1).Value = "./*[position() <= " & (CStr(intPage) * intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]" 
   redisplay (intPage) 
   End If 

   End Function 

'' The treatment of "first page"
   Function FirstPage() 

   ("//@OnClick")(1).Value = "previousPage(1)" 
   ("//@OnClick")(2).Value = "nextPage(1)" 
   ("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]" 
   transform() 
   setPageCount() 

   End Function 

'' The processing of "last page"
   Function LastPage() 

   Dim intTotalPages 
   Dim intTotalRecords 

   intTotalPages = getNumberOfPages(intTotalRecords) 
   nextPage (intTotalPages - 1) 

   End Function 
   </Script> 
   </Head> 
   <body> 
<p align="center" style="font-weight:bold;font-size:12pt;color:#0000FF;border-bottom:3px double red;padding-bottom:5px">Customer relationship table</p>
   <XML id=''Data''> 
<Customer Relations Table xmlns:dt="urn:schemas-microsoft-com:datatypes">
<Customer><serial number dt:dt="int">01</serial number><name>Mi</name><email>water@</email></client>
<Customer><Serial No. dt:dt="int">02</Serial No.><Name>uyi</Name><Email>Lily@</Email></Customer>
<Customer><Serial No. dt:dt="int">03</Serial No.><Name>uiyu</Name><Email>John@</Email></Customer>
<Customer><Serial No. dt:dt="int">04</Serial No.><Name>Doug</Name><Email>Karry@</Email></Customer>
<Customer><Serial No. dt:dt="int">05</Serial No.><Name>Ellen</Name><Email>vivki@</Email></Customer>
<Customer><Serial No. dt:dt="int">06</Serial No.><Name>Frank</Name><Email>net_lover@</Email></Customer>
<Customer><Serial No. dt:dt="int">07</Serial No.><Name>Greg</Name><Email>meng@</Email></Customer>
<Customer><Serial No. dt:dt="int">08</Serial No.><Name>Harry</Name><Email>sunny@</Email></Customer>
<Customer><Serial No. dt:dt="int">09</Serial No.><Name>Ingrid</Name><Email>cathy@</Email></Customer>
<Customer><Serial No. dt:dt="int">10</Serial No.><Name>Jeff</Name><Email>your@</Email></Customer>
<Customer><Serial No. dt:dt="int">11</Serial No.><Name>Kelly</Name><Email>Iloveyou@</Email></Customer>
<Customer><Serial No. dt:dt="int">12</Serial No.><Name>Larry</Name><Email>smilling@</Email></Customer>
<Customer><Serial No. dt:dt="int">13</Serial No.><Name>Mark</Name><Email>money@</Email></Customer>
<Customer><Serial No. dt:dt="int">14</Serial No.><Nancy</Name><Email>www@</Email></Customer>
<Customer><Serial No. dt:dt="int">15</Serial No.><Name>Peter</Name><Email>dotnet@</Email></Customer>
<Customer><Serial No. dt:dt="int">16</Serial No.><Name>Rachel</Name><Email>billgates@</Email></Customer>
<Customer><Serial No. dt:dt="int">17</Serial No.><Name>Seth</Name><Email>flying@</Email></Customer>
<Customer><Serial No. dt:dt="int">18</Serial No.><Name>Tim</Name><Email>agooyboy@</Email></Customer>
</Customer Relations List>
   </XML> 
   <XML id=''Style'' src=''''></XML> 
   <div ></div> 
   <table border="0" width="100%" style="font-size:11pt;"> 
   <tr> 
<td align="right">Source: [<a href="">Meng Xianhui's Wonderful World</a>]</td>
   </tr> 
   </table> 
   </body> 
   </HTML> 

Copy the above content to the local computer and save it as the corresponding files respectively. You can see the effect in the IE5+ and XML3.0+ environment!