Subject: Re: [xsl] xslt transform sql into html tables for dhtml paging From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 24 Jan 2002 10:46:39 +0000 |
Hi Dave, > its a really cool solution - not sure how textbook to XSLT usage it > is... but it works and is pretty speedy and it uses templates > instead of trying to think procedurally through the problem - though > I use alot of variables to determine Record Totals and Page #'s and > the Page Total count for this set of records when divided by the > variable set for determining how many recs to show per page/per > table. Just to illustrate another method to you... If you know that each table takes $cnstPageRec records, then you know that the 1st, ($cnstPageRec + 1)th, ($cnstPageRec * 2 + 1)th and so on records form the first record in each table. You can locate these records within your $sqlrecords set using: $sqlrecords[position() mod $cnstPageRec = 1] So rather than working out how many tables there are explicitly, you could just iterate over the first records of each table, as follows: <xsl:for-each select="$sqlrecords[position() mod $cnstPageRec = 1]"> ... </xsl:for-each> But now xsl:number will give you the wrong number for the page, because xsl:number always gives you the number of the current node within the source tree (in this case amongst its siblings). But that doesn't matter, because you can use position() instead, to give you the page number: <xsl:for-each select="$sqlrecords[position() mod $cnstPageRec = 1]"> <div id="page{position()}"> ... <tr> <td> Page <xsl:value-of select="position()" /> of <xsl:value-of select="last()" /> | Total: <xsl:value-of select="count($sqlrecords)" /> goals </td> </tr> </div> </xsl:for-each> I'm not sure what you're doing within your rows template, but the advantage of picking out the first row of each table is that you can easily get the next $cnstPageRec - 1 rows to complete the table with the following-sibling axis, as follows: <xsl:for-each select="$sqlrecords[position() mod $cnstPageRec = 1]"> <div id="page{position()}"> <xsl:for-each select=". | following-sibling::z:row [position() < $cnstPageRec]"> ... create the row ... </xsl:for-each> <tr> <td> Page <xsl:value-of select="position()" /> of <xsl:value-of select="last()" /> | Total: <xsl:value-of select="count($sqlrecords)" /> goals </td> </tr> </div> </xsl:for-each> Or of course you could apply templates to the z:row elements: <xsl:for-each select="$sqlrecords[position() mod $cnstPageRec = 1]"> <div id="page{position()}"> <xsl:apply-templates select=". | following-sibling::z:row [position() < $cnstPageRec]" /> <tr> <td> Page <xsl:value-of select="position()" /> of <xsl:value-of select="last()" /> | Total: <xsl:value-of select="count($sqlrecords)" /> goals </td> </tr> </div> </xsl:for-each> You may find that this method is faster, since there are less calculations to perform and in particular you aren't looking through the same set of $sqlrecords again and again to pull out different ranges. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xslt transform sql into h, Jonathan Perret | Thread | [xsl] skipping page numbers in fo, Lance Frohman |
Re: [xsl] which XML parser is the f, Steve Muench | Date | [xsl] xslt and fuzzy logic, Bryan Rasmussen |
Month |