Making balanced two-column tables from one-column data

Subject: Making balanced two-column tables from one-column data
From: Philip Borenstein <pb@xxxxxxxxxx>
Date: Wed, 19 Jan 2000 13:35:12 -0500
I have a solution to my problem, but it seems so un-XSLT-like, and ugly that
I'm sure there must be a better solution. i think that part of the problem
is that I just don't "get" XPaths. Pointers to good XPath learning resources
much appreciated.

I have the following XML:


I want to produce a two-column table like this:

  A   G
  B   H
  C   I
  D  J
  E  K

(The number of COMPONENTS may or may not be even.)

This is my XSL template for the COMPONENT element:

<xsl:template match="COMPONENTS">
  <P>There are <xsl:value-of select="count(COMPONENT)"/> components.</P>
     <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">
                  <TD><xsl:value-of select="../COMPONENT[position()=$p]"
                  <TD><xsl:value-of select="../COMPONENT[position()=$p+$h]"

This just strikes me as the wrong way to go about it.

--philip borenstein.

 XSL-List info and archive:

Current Thread