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

RE: Making balanced two-column tables from one-column data

Subject: RE: Making balanced two-column tables from one-column data
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Wed, 19 Jan 2000 12:56:21 -0700
xsl table two columns
> <xsl:template match="COMPONENTS">
>   <P>There are <xsl:value-of select="count(COMPONENT)"/> 
> components.</P>
>   <TABLE>
>      <xsl:variable name="h" select="round(count(COMPONENT) div 2)" />
>      <xsl:for-each select="COMPONENT">
>        <xsl:variable name="p" select="position()" /> 
>        <xsl:if test="$h>=$p">
>            <TR>
>                   <TD><xsl:value-of 
> select="../COMPONENT[position()=$p]"
> /></TD>
>                   <TD><xsl:value-of 
> select="../COMPONENT[position()=$p+$h]"
> /></TD>
>             </TR>
>          </xsl:if>
>       </xsl:for-each>
>   </TABLE>
> </xsl:template>
> This just strikes me as the wrong way to go about it.

Since HTML tables have to be created row by row, your options are limited.
This isn't much better, but your code can be optimized like this:

  <xsl:for-each select="COMPONENT[position() lt;= ceiling(count(COMPONENT)
div 2)]">
      <TD><xsl:value-of select="."/></TD>
          <xsl:when test="following-sibling::COMPONENT">
            <xsl:value-of select="following-sibling::COMPONENT"/>

Note that the last cell will have a non-breaking space character in the
event there is an odd number of COMPONENTs.

 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.