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

Re: Balancing Columns

Subject: Re: Balancing Columns
From: naha@xxxxxxxxxx
Date: Thu, 24 Jan 2002 10:52:02 -0500 (EST)
xsl for each row count
Quoting "W. Eliot Kimber" <eliot@xxxxxxxxxx>:

[...]

> I think you've misunderstood what I mean by "balanced columns". I don't
> mean columns of equal width, but columns in which the composed text is
> of equal depth across the columns, e.g.:
> 
> 
>      xxxxxxxxxxx      xxxxxxxxxx     xxxxxxxxxx
>      xxxxxxxxxxx      xxxxxxxxxx     
> 
> Not:
> 
>      xxxxxxxxxxx      xxxxxxxxxx
>      xxxxxxxxxxx
>      xxxxxxxxxxx
>      xxxxxxxxxxx

Here's a snippet from one of my transformations.  I think something like this 
is what you're looking for.  It outputs a list of items (passed in through the 
tracked-tickers parameter) as columns in a table.


    <!-- Output an HTML table of all tracked stocks.  The table should
         have no more than $tracked-tickers-max-columns columns and at
         least $tracked-tickers-min-rows rows (unless there are fewer
         than that many ticker symbols).  Each ticker symbol is linked
         to its Yahoo quotes page.
         -->
    <xsl:template name="list-tracked-stocks">
        <xsl:param name="tracked-tickers"></xsl:param>
        <!-- $tracked-tickers might contain the ticker-symbol elements
             of track-stock elements or the ticker attributes of stock-info
             elements. -->
        <xsl:variable name="sorted-tickers-rtf">
            <xsl:for-each select="$tracked-tickers">
                <xsl:sort select="string()" data-type="text" order="ascending"/>
                <xsl:variable name="ticker" select="string()"/>
                <!-- need to make sure $ticker is non-empty -->
                <xsl:if test="boolean($ticker)">
                    <!-- need to make sure there are no duplicates in
                         $tracked-tickers -->
                    <xsl:if test="generate-id(.) =
                                  generate-id($tracked-tickers[string()=$ticker]
[1])">
                        <ticker-symbol>
                            <xsl:value-of select="$ticker"/>
                        </ticker-symbol>
                    </xsl:if>
                </xsl:if>
            </xsl:for-each>
        </xsl:variable>
        <xsl:variable name="sorted-tickers"
                      select="saxon:node-set($sorted-tickers-rtf)"/>
        <xsl:variable name="cell-count"
                      select="count($sorted-tickers/ticker-symbol)"/>
        <!-- $tracked-tickers-max-columns $tracked-tickers-min-rows -->
        <xsl:variable name="row-count-1"
                      select="$cell-count div $tracked-tickers-max-columns"/>
        <xsl:variable name="row-count">
            <xsl:choose>
                <xsl:when test="$row-count-1 &gt; $tracked-tickers-min-rows">
                    <xsl:value-of select="ceiling($row-count-1)"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$tracked-tickers-min-rows"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="column-count"
                      select="ceiling($cell-count div $row-count)"/>
        <table border="0">
            <!-- for $row-number from 1 to $row-count -->
            <xsl:for-each select="$sorted-tickers/ticker-symbol[position()
                                  &lt; ($row-count + 1)]">
                <xsl:variable name="row-number" select="position()"/>
                <tr>
                    <!-- for $column-number from 1 to $column-count -->
                    <xsl:for-each select="$sorted-tickers/ticker-symbol[position
()
                                          &lt; ($column-count + 1)]">
                        <xsl:variable name="column-number"
                                      select="position()"/>
                        <xsl:variable name="this"
                                      select="$sorted-tickers/ticker-symbol
[position() =
                                              ($row-number +
                                              (($column-number - 1)
                                              * $row-count))]"/>
                        <td>
                            <xsl:choose>
                                <xsl:when test="$this">
                                    <xsl:call-template name="make-yahoo-href">
                                        <xsl:with-param name="ticker-symbol"
                                                        select="$this"/>
                                    </xsl:call-template>
                                </xsl:when>
                                <xsl:otherwise>
                                </xsl:otherwise>
                            </xsl:choose>
                            <!-- provide adequate spacing between columns -->
                            <xsl:text>&#160;</xsl:text>
                            <xsl:text>&#160;</xsl:text>
                            <xsl:text>&#160;</xsl:text>
                            <xsl:text>&#160;</xsl:text>
                            <xsl:text>&#160;</xsl:text>
                        </td>
                    </xsl:for-each>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>




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


Current Thread

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.