[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2857
  • Last Modified:

Help with pagination in xsl file?

I was peeking at some other pagination posts, and couldn't quite figure out how to fit the xsl pagination into the code. How can I paginate the code in xsl, say, 6 records per page, with previous and next buttons or links for the user?

The top of my code currently looks like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:fx="#fx-functions" exclude-result-prefixes="msxsl fx">
    <xsl:output method="html" version="4.0" indent="yes" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
    <xsl:template match="//dataroot" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <html>
            <head>
                <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=UTF-8"/>
                <title>scv-central</title>
                <style type="text/css">
                 </style>
           </head>
            <body link="#0000ff" vlink="#800080">
                <xsl:variable name="GlobalGroup" select="Qscv-central"/>
                <!-- Calculate expressions and running sums -->
                <xsl:value-of select="fx:CalculateExpressions_Global($GlobalGroup[1], $GlobalGroup)"/>
                <div style="BORDER-STYLE: none; WIDTH: 3.5in; BACKGROUND-COLOR: #ece9d8; VISIBILITY: visible; HEIGHT: 0in; POSITION: relative">
                </div>
                <xsl:for-each select="Qscv-central">
                    <xsl:sort select="Area" order="ascending" data-type="text"/>
                    <xsl:sort select="Rent" order="ascending" data-type="number"/>
                    <!-- Calculate expressions and running sums -->
                    <xsl:value-of select="fx:CalculateExpressions_Detail(., $GlobalGroup)"/>
                    <div style="BORDER-STYLE: none; WIDTH: 3.5in; BACKGROUND-COLOR: #ebebeb; VISIBILITY: visible; HEIGHT: 3.25in; POSITION: relative">
                        <span class="Style0" style="LEFT: 0.0833in; TOP: 0.0833in; WIDTH: 0.6666in; HEIGHT: 0.177in; POSITION: absolute">
                            <xsl:value-of select="Area"/>
                        </span>
                        <span class="Style1" style="LEFT: 1.8229in; TOP: 0.0729in; WIDTH: 1.6041in; HEIGHT: 0.1875in; OVERFLOW: hidden; POSITION: absolute">
                            <xsl:value-of select="Address"/>
                        </span>

It goes on from there. And the xml for one record looks like this (there are more fields in each record, but I just made it shorter for expediency purposes):

<Qscv-central>
        <Print>1</Print>
        <SMA>SCV</SMA>
        <New>0</New>
        <SS>0</SS>
        <Area>Central</Area>
        <Address>1701 Industrial Street</Address>
        <Rent>0</Rent>
</Qscv-central>

Thank you!
0
APConnextion
Asked:
APConnextion
  • 5
  • 3
2 Solutions
 
Duane LawrenceCommented:
I found a couple of examples that will help.

http://www.perfectxml.com/XSLFO.asp

http://forums.devshed.com/t54150/s.html

Duane
0
 
APConnextionAuthor Commented:
I peeked at those.  I ended up using this:

http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20537316.html?query=pagination+in+xml&clearTAFilter=true

But it's coming up with an error that says:
msxml4.dll error '80004005'

The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.

/scv/central.asp, line 21

Can someone help me with this?  My xsl now looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet[
<!ENTITY newLine    "&#10;">
<!ENTITY headerCo   "    CENTRAL REPORT     Page: ">
]>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:fx="#fx-functions" exclude-result-prefixes="msxsl fx">
    <xsl:output method="html" version="4.0" indent="yes" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
    <xsl:param name= "numberperpage" select="3" />
    <xsl:template match="//dataroot" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <html>
            <head>
                <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=UTF-8"/>
                <title>scv-central</title>
                <style type="text/css">
                </style>
            </head>
            <body link="#0000ff" vlink="#800080">
                <xsl:variable name="GlobalGroup" select="Qscv-central"/>
                <!-- Calculate expressions and running sums -->
                <xsl:value-of select="fx:CalculateExpressions_Global($GlobalGroup[1], $GlobalGroup)"/>
                <div style="BORDER-STYLE: none; WIDTH: 3.5in; BACKGROUND-COLOR: #ece9d8; VISIBILITY: visible; HEIGHT: 0in; POSITION: relative">
                </div>
                <xsl:for-each select="Qscv-central">
                    <xsl:sort select="Area" order="ascending" data-type="text"/>
                    <xsl:sort select="Rent" order="ascending" data-type="number"/>
                    <!-- Calculate expressions and running sums -->
                    <xsl:value-of select="fx:CalculateExpressions_Detail(., $GlobalGroup)"/>
                   
                    <xsl:if test="position() mod $numberperpage = 1"><xsl:text>&headerCo;</xsl:text><xsl:value-of select="((position() + $numberperpage)-1) div $numberperpage"/>          
                              <xsl:text>&newLine;</xsl:text>
                 </xsl:if>

The asp page looks like this:
<%
Set objData = CreateDOM
objData.async = false

if (false) then
      Set objDataXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
      objDataXMLHTTP.open "GET", "", false
      objDataXMLHTTP.setRequestHeader "Content-Type", "text/xml"
      objDataXMLHTTP.send
      objData.load(objDataXMLHTTP.responseBody)
else
      objData.load(Server.MapPath("Central.xml"))
end if

Set objStyle = CreateDOM
objStyle.async = false
objStyle.load(Server.MapPath("Central.xsl"))
Session.CodePage = 65001

Response.ContentType = "text/html"
Response.Write objData.transformNode(objStyle)

Function CreateDOM()
      On Error Resume Next
      Dim tmpDOM

      Set tmpDOM = Nothing
      Set tmpDOM = Server.CreateObject("MSXML2.DOMDocument.5.0")
      If tmpDOM Is Nothing Then
            Set tmpDOM = Server.CreateObject("MSXML2.DOMDocument.4.0")
      End If
      If tmpDOM Is Nothing Then
            Set tmpDOM = Server.CreateObject("MSXML.DOMDocument")
      End If
      
      Set CreateDOM = tmpDOM
End Function
%>

Does someone know what I'm missing? I know it has to be close . . .



0
 
APConnextionAuthor Commented:
And I still don't know about the next and previous links . . .
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Duane LawrenceCommented:
msxml4.dll error '80004005'

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q316297
CAUSE
The content model of a type definition in the XSD is non-deterministic (ambiguous). For additional information about deterministic content models, see the "More Information" section of this article.
RESOLUTION
Identify the type definition that contains the non-deterministic content model and make the changes required to make the content model deterministic (unambiguous).


In plain english, the definition of your xsl has a problem.  I will look for it on my end also, but I wanted to get this up so you can read it.

Duane
0
 
APConnextionAuthor Commented:
Thank you Duane. It seemed to stem from adding the DOCTYPE section at the top of the xsl document. Before I added that (and the corresponding bits a little further down the xsl), it came up without an error, but put the number 1, then three records, then the number 2, and three records, and so on. Not on seperate pages, tho. Just scrolling down. It divided them into three's and numbered them.

Do you know how we can fix this? Your help is much appreciated.
0
 
APConnextionAuthor Commented:
Actually, I don't think this code is doing what I want it to. How do I get a page break in there after the groups of records and have previous and next links for the pages? Help!
0
 
Duane LawrenceCommented:
Here is an example that uses PHP and MySQL, you won't be able to cut and paste and use the code, but if you read it and learn from it you can use it.

http://www.tonymarston.net/php-mysql/xsl.html

I have spend hours trying to help, I have to make a living, I am done with this thread.

Duane
0
 
APConnextionAuthor Commented:
I will take a look at that. My apologies for taking your time. I've appreciated your help though. And I've been doing quite a bit of reading, on and offline. Hundreds of pages trying to figure out how to make this and numerous other things happen. Mainly dealing with XML, VB, and PHP.
0
 
rdcproCommented:
Well, since this is such a common question, I decided to take the time to set up an example.   But first, a couple comments on your code.

In your ASP code don't use:

     Set objDataXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")

This is not server safe.  Use:

     Set objDataXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
or any other version, 3 or higher.  

Also, this:

     If tmpDOM Is Nothing Then
          Set tmpDOM = Server.CreateObject("MSXML.DOMDocument")
     End If

is not a valid progId.  It's:

     If tmpDOM Is Nothing Then
          Set tmpDOM = Server.CreateObject("MSXML2.DOMDocument")
     End If

This creates the "version independant" parser, which is probably MSXML 3.0, unless you don't have MSXML 3.0 but do have 2.6 (a pretty rare situation).

I would say that in most cases, server side you'll want to use MSXML 4.  Use MSXML 5 if  you're working with Office documents.  On the server you should already know what parser you have, so I don't see an advantage in falling back to older versions.

As far as your paging issues go, MSXML does not support creating multiple output files.  If that's really  your goal, Oleg Tkachenko wrote an MSDN magazine article a while back on how to get the .NET parser to do this.  

But an ASP based paging solution needs to set a parameter during the transformation, unless you've got the paging done in the datasource that creates the XML.  

I've created an example that does this.  It uses an XML document generated from the Northwind sample database that looks like:

<CustOrders xmlns:sql="urn:schemas-microsoft-com:xml-sql">
      <Customers>
            <CustomerID>ALFKI</CustomerID>
            <CompanyName>Alfreds Futterkiste</CompanyName>
            <ContactName>Maria Anders</ContactName>
            <ContactTitle>Sales Representative</ContactTitle>
            <Address>Obere Str. 57</Address>
            <City>Berlin</City>
            <PostalCode>12209</PostalCode>
            <Country>Germany</Country>
            <Phone>030-0074321</Phone>
            <Fax>030-0076545</Fax>
      </Customers>
      <Customers>
            <CustomerID>ANATR</CustomerID>
            <CompanyName>Ana Trujillo Emparedados y helados</CompanyName>
            <ContactName>Ana Trujillo</ContactName>
            <ContactTitle>Owner</ContactTitle>
            <Address>Avda. de la Constitución 2222</Address>
            <City>México D.F.</City>
            <PostalCode>05021</PostalCode>
            <Country>Mexico</Country>
            <Phone>(5) 555-4729</Phone>
            <Fax>(5) 555-3745</Fax>
      </Customers>


The ASP page reads the querystring, and sets the current page and the number of records to display per page.  It then calls the transformation that renders the correct page of data, and sets up a set of links so that you can navigate through the other pages.  You can find it at:

http://rdcpro.com/Members/rdcpro/snippets/xsltpaging/

Regards,
Mike Sharp
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now