Terrence Brannon wrote:


> What if a website had a "mywebsite" section where each user could
> set the height of their screen? How might we take an XML version
> (say, docbook) version of an article and paginate it so each part
> would fit on their screen and hitting next would move into the
> next segment of the article? 

Here's an example of a "paginator" XSLT stylesheet for record-oriented

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
<xsl:output method="html" />
<xsl:param name="start">1</xsl:param>
<xsl:param name="perpage">10</xsl:param>
<xsl:variable name="totalitems" select="count(//item)"/>

<xsl:variable name="end">
    <xsl:when test="($start + $perpage) &gt; $totalitems">
      <xsl:value-of select="$totalitems"/>
      <xsl:value-of select="$start + $perpage - 1"/>

<!-- begin root template -->
<xsl:template match="/">

  <h3>Showing records <xsl:value-of select="$start"/> - <xsl:value-of
select="$end"/> of 
  <xsl:value-of select="$totalitems"/></h3> 

  <table border="0" cellpadding="0" cellspacing="0">
    <tr><th>Product ID</th><th>Description</th><th>Price</th></tr>
    <xsl:for-each select="/order/item[position() >= $start and
position() &lt;= $end]">
        <td><xsl:value-of select="@product-id"/></td>
        <td><xsl:value-of select="name"/></td>     
        <td><xsl:value-of select="price"/></td>

  <!-- if there are records before the block we are viewing, provide a
'prev.' link -->
  <xsl:if test="$start > 1">
    <a href="paginate.xml?start={$start -

  <!-- process *all* the <item> elements in the document to build the
       'google-style' navbar -->
  <xsl:apply-templates select="/order/item"/>

  <!-- if there are more records, provide a 'next' link -->
  <xsl:if test="$totalitems > $end">
    <a href="paginate.xml?start={$end + 1};perpage={$perpage}">next</a>

<!-- end root template -->

<!-- the 'item' template that builds the numbered navbar links -->
<xsl:template match="item">
  <xsl:if test="position() mod $perpage = 1 or $perpage = 1">
    <xsl:variable name="pagenum">
      <xsl:value-of select="ceiling(position() div $perpage)"/>
    <a href="paginate.xml?start={position()};perpage={$perpage}"> 
      <xsl:value-of select="$pagenum"/>
      <!-- force whitespace in between the numbered links -->
      <xsl:text> </xsl:text>


Obviously, yours will look quite different if you are carving up a
DocBook XML document, but this should give you enough ideas to get you


To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to