[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Building tables with XSLT

Subject: Re: Building tables with XSLT
From: "Carsten Klein" <carstenklein@xxxxxxxx>
Date: Tue, 10 Sep 2002 09:57:46 +0200
xslt 2 columns
Hi Dan,

well, its quite easy, all you need to do is get familiar with recursive
templates.

here's the stylesheet, I have tested it and it worked ok. I commented some
parts of the code, this should reduce the overall size.

<?xml version="1.0"?>
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- defaults to first images in database : 1 -->
    <xsl:param name="start" select="'1'"/>
    <!-- defaults to 5 columns / row: 5 -->
    <xsl:param name="columns" select="'5'"/>
    <!-- defaults to 15 images / page, that is, 3 rows / page -->
    <xsl:param name="count" select="'15'"/>

    <!-- These parameters then would need some adjustments, namely, declare
a global variable which holds
            the number of rows to be displayed

            $count div $columns = $rows
    -->
    <xsl:variable name="rows" select="$count div $columns"/>

<xsl:template match="/">
    <xsl:call-template name="displayRows">
        <xsl:with-param name="dr_start" select="$start"/>
        <xsl:with-param name="dr_columns" select="$columns"/>
        <xsl:with-param name="dr_rows" select="$rows"/>
    </xsl:call-template>
</xsl:template>

<xsl:template name="displayRows">
    <xsl:param name="dr_start"/>
    <xsl:param name="dr_columns"/>
    <xsl:param name="dr_rows"/>

    <!-- we are counting from n to 0 downwards here -->
    <xsl:if test="$dr_rows > 0">
        <tr>
            <!-- display the columns -->
                <!-- adjust start, so that it correctly adjusts to all the
                       rows and columns being displayed previously

                        that is: the new start position (the image number)
                        is equal to:

                            $pr_rows = ($rows - $dr_rows) : number of
already processed rows

                            $start = ($pr_rows * $columns) + $start

                            the new start position for the next row and its
columns.

                        test:

                            first run, rows=2, columns=5 , start = 15

                                    ((2 - 2) * 5) + 15 = 0*5 + 15 = 15 :
correct, first row
                                    ((2 - 1) * 5) + 15 = 1*5 + 15 = 20 :
correct, second row
                                    ((2 - 0) * 5) + 15 = 2*5 + 15 = 25 :
correct, third row, if there were any


                -->
            <xsl:call-template name="displayCells">
                <xsl:with-param name="dc_start" select="$start + (($rows -
$dr_rows) * $dr_columns)"/>
                <xsl:with-param name="dc_columns" select="$dr_columns"/>
                <xsl:with-param name="dc_current_row" select="$rows -
$dr_rows"/>
            </xsl:call-template>

        </tr>

<xsl:comment>end of row</xsl:comment>

        <!-- next row -->
        <xsl:call-template name="displayRows">
            <xsl:with-param name="dr_start" select="$start + (($rows -
$dr_rows) * $dr_columns)"/>
            <xsl:with-param name="dr_columns" select="$dr_columns"/>
            <xsl:with-param name="dr_rows" select="$dr_rows - 1"/>
        </xsl:call-template>

    </xsl:if>
</xsl:template>

<xsl:template name="displayCells">
    <!-- the position of the image to be displayed in this cell -->
    <xsl:param name="dc_start"/>
    <!-- the number of columns to be displayed -->
    <xsl:param name="dc_columns"/>
    <!-- the number of the current row, for convenience -->
    <xsl:param name="dc_current_row"/>

    <xsl:if test="$dc_columns > 0">
        <xsl:variable name="CELL" select="IMAGES/IMAGE[$dc_start]"/>
        <xsl:choose>
            <xsl:when test="$CELL">
                <td align="center" valign="middle">
                    <img src="{$CELL}" height="{$CELL/@HEIGHT}"
width="{$CELL/@WIDTH}" border="0"/>
                </td>
            </xsl:when>
            <xsl:otherwise>
                <td>&#160;</td>
            </xsl:otherwise>
        </xsl:choose>

        <!-- next cell -->
        <xsl:call-template name="displayCells">
               <xsl:with-param name="dc_start" select="$dc_start + 1"/>
               <xsl:with-param name="dc_columns" select="$dc_columns - 1"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • Building tables with XSLT
    • Dan Henke - Tue, 10 Sep 2002 02:44:25 -0400 (EDT)
      • juggy - Tue, 10 Sep 2002 03:06:47 -0400 (EDT)
      • juggy - Tue, 10 Sep 2002 03:13:37 -0400 (EDT)
      • juggy - Tue, 10 Sep 2002 03:18:22 -0400 (EDT)
      • Carsten Klein - Tue, 10 Sep 2002 03:54:51 -0400 (EDT) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.