Click here to Skip to main content
13,004,188 members (105,242 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads


34 bookmarked
Posted 27 Jan 2004

XML paging using XML + XSL + CSS

, 27 Jan 2004
Send params to an XSL file
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath

Public Class XMLReader
    Inherits System.Web.UI.Page

    Public xmlDoc As New XmlDocument
    Public xslDoc As New Xml.Xsl.XslTransform
    Public pageSize As String = 5

    Public Sub initXml()
        Dim xmlDocStr = Request.PhysicalApplicationPath & "guestbook.xml"
        Dim xslDocStr = Request.PhysicalApplicationPath & "guestbook.xsl"

        ' Load the dom
        If File.Exists(xmlDocStr) Then
            Catch e As Exception
                Response.Write("<B>Error in XML File:</b> " & e.Message)
            End Try
        End If

        ' Load the xsl
        If File.Exists(xslDocStr) Then
            Catch e As Exception
                Response.Write("<B>Error in XSL File:</b> " & e.Message)
            End Try
            Response.Write("<B>Error in XSL File:</b> file not found.")
        End If
    End Sub

    Public Function buildPageHTML()
        Dim counter = 1
        Dim pagelink = ""

        Dim allNodes As XmlNodeList = xmlDoc.SelectNodes("//guestbook/entry")

        Dim pages As Integer = allNodes.Count / pageSize
        If pages <> Int(pages) Then pages = Int(pages) + 1

        For counter = 1 To pages + 1
            pagelink &= "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?page=" & counter & """>" & counter & "</a>&#160;"

        Return pagelink
    End Function

    Public Function Display()
        Dim currentPage = Request.QueryString("page")
        Dim xsltParams As New XsltArgumentList
        If currentPage = 0 Then currentPage = 1

        If currentPage - 1 = 0 Then
            xsltParams.AddParam("start", "", 1)
            xsltParams.AddParam("start", "", ((currentPage - 1) * pageSize) + 1)
        End If

        xsltParams.AddParam("end", "", ((currentPage - 1) * pageSize) + pageSize)
        xsltParams.AddParam("link", "", buildPageHTML)

            xslDoc.Transform(xmlDoc, xsltParams, Response.OutputStream, Nothing)
        Catch e As Exception
        End Try
    End Function

    Private Sub XMLReader_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Matthew Hazlett
Web Developer
United States United States
I started programming for fun when I was about 10 on an Franklin Ace 1000.

I still do it just for fun but it has gotten me a few jobs over the years. More then I can say for my Microsoft Certifications. Smile | :)

The way I learned was by example, now its time to give back to the next generation of coders.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170627.1 | Last Updated 28 Jan 2004
Article Copyright 2004 by Matthew Hazlett
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid