Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Aug 2002
    Thanked 0 Times in 0 Posts

    display records in certain number of rows.

    i need to use xsl to display the xml output in certain number of rows. for example, i have 30 rows and i want to display 10 rows in each page. the param "start" is a default value, and thus it does not change from 1 ("start") to 11 when it reaches to the 11th record.

    this is the code:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

    <xsl:output method="html" />
    <xsl:param name="start">1</xsl:param>
    <xsl:param name="perpage">10</xsl:param>

    <xsl:variable name="totalitems" select="count(//student)"/>
    <xsl:variable name="end">
    <xsl:when test="($start + $perpage) > $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="school/student[position() >= $start and
    position() <= $end]">
    <td><xsl:value-of select="name"/></td>

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

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

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


    <!-- end root template -->

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


    pls help asap...
    Note: is it possible to do a counter or something.

    Edited to remove the excessive smlileys from your code (where you didn't intend for them to be of course) :) .
    Last edited by boxer_1; 09-07-2002 at 01:30 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts