[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(.) =
                            <xsl:value-of select="$ticker"/>
        <xsl:variable name="sorted-tickers"
        <xsl:variable name="cell-count"
        <!-- $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:when test="$row-count-1 &gt; $tracked-tickers-min-rows">
                    <xsl:value-of select="ceiling($row-count-1)"/>
                    <xsl:value-of select="$tracked-tickers-min-rows"/>
        <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()"/>
                    <!-- 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"
                        <xsl:variable name="this"
[position() =
                                              ($row-number +
                                              (($column-number - 1)
                                              * $row-count))]"/>
                                <xsl:when test="$this">
                                    <xsl:call-template name="make-yahoo-href">
                                        <xsl:with-param name="ticker-symbol"
                            <!-- provide adequate spacing between columns -->

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

Current Thread


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.
First Name
Last Name
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.