Click here to Skip to main content
15,867,308 members
Articles / Web Development / ASP.NET
Article

XML paging using XML + XSL + CSS

Rate me:
Please Sign up or sign in to vote.
4.29/5 (6 votes)
27 Jan 2004 73.6K   1.2K   34   6
Send params to an XSL file

Introduction

Hello again, I decided to take a break from graphics and do some XML. I created an XML Pager, what it does is read an XML file and apply an XSL translation and send params to it to create a paged document.

Important, you need to have ASP.NET 1.1 running on your server! ASP.NET 1.0 had a bug in the XSL module. If you have 1.0 and try to run this, Windows will report a call to a nonexistent function.

How it's done

All you have to do is create a new XmlDocument object and an XslTransform object. Load them with data and call the Transform method. Below is a sample:

VB
Dim xmlDoc As New XmlDocument
Dim xslDoc As New XslTransform 

xmlDoc.Load("mydoc.xml")
xslDoc.Load("mydoc.xsl") 

xslDoc.Transform(xmlDoc, nothing, Response.OutputStream, Nothing)

Sending Params to the XSL

Everything is exactly the same as the above example except that you create another object called XsltArgumentList.

VB
Dim xmlDoc As New XmlDocument
Dim xslDoc As New XslTransform 
Dim xslArgs as new XsltArgumentList

xmlDoc.Load("mydoc.xml")
xslDoc.Load("mydoc.xsl") 

xsltParams.AddParam("start", "", 1)
xsltParams.AddParam("end", "", 5)
xslDoc.Transform(xmlDoc, xsltParams, Response.OutputStream, Nothing)

The XSL File

XML
<xsl:stylesheet version="1.0" xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>">
<xsl:param name="start"/>
<xsl:param name="end"/>
<xsl:param name="link"/>
<xsl:template match="/">
<html>
<head>
  <link href="guestbook.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <xsl:for-each 
    select="//guestbook/entry[position()>=$start and $end>=position()]">
  <div id="guestbook">
    <div class="head"><xsl:value-of select="title"/></div>
    <div class="body"><xsl:value-of select="text"/></div>
    <div class="footer">
      <xsl:value-of select="date"/>&#160;<xsl:value-of select="email"/></div>
    </div>
  </xsl:for-each> 
  <xsl:value-of select="$link" disable-output-escaping="yes"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

You specify the params at the top of the file and then just use them like regular vars.

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


Written By
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.



Comments and Discussions

 
QuestionHow can i run this project Pin
sanjaythakur61114-Feb-18 18:03
sanjaythakur61114-Feb-18 18:03 
QuestionRegarding paging Pin
Tridip Bhattacharjee31-Jul-15 9:07
professionalTridip Bhattacharjee31-Jul-15 9:07 
Questionhi Pin
priya_chauhan0912-Oct-11 19:03
priya_chauhan0912-Oct-11 19:03 
GeneralExcellent man Pin
i_islamian10-Nov-09 22:16
i_islamian10-Nov-09 22:16 
Generalasp.net 2 Pin
imperialx15-Jun-07 2:30
imperialx15-Jun-07 2:30 
GeneralSorry, the link is fixed... Pin
Matthew Hazlett29-Jan-04 9:46
Matthew Hazlett29-Jan-04 9:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.