Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version
Go to top

XML paging using XML + XSL + CSS

, 27 Jan 2004
Send params to an XSL file
XMLPage.zip
guestbook.xsl
src
bin
XMLRead.dll
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
            Try
                xmlDoc.Load(xmlDocStr)
            Catch e As Exception
                Response.Write("<B>Error in XML File:</b> " & e.Message)
                Response.End()
            End Try
        Else
            xmlDoc.LoadXml("<guestbook></guestbook>")
        End If

        ' Load the xsl
        If File.Exists(xslDocStr) Then
            Try
                xslDoc.Load(xslDocStr)
            Catch e As Exception
                Response.Write("<B>Error in XSL File:</b> " & e.Message)
                Response.End()
            End Try
        Else
            Response.Write("<B>Error in XSL File:</b> file not found.")
            Response.End()
        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;"
        Next

        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)
        Else
            xsltParams.AddParam("start", "", ((currentPage - 1) * pageSize) + 1)
        End If

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

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


    Private Sub XMLReader_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        initXml()
    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.

License

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

Share

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.
 


| Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 28 Jan 2004
Article Copyright 2004 by Matthew Hazlett
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid