[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
> <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: <TABLE> <xsl:for-each select="COMPONENT[position() lt;= ceiling(count(COMPONENT) div 2)]"> <TR> <TD><xsl:value-of select="."/></TD> <TD> <xsl:choose> <xsl:when test="following-sibling::COMPONENT"> <xsl:value-of select="following-sibling::COMPONENT"/> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </TD> </TR> </xsl:for-each> </TABLE> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|