Subject: RE: Making balanced two-column tables from one-column data From: Linda van den Brink <lvdbrink@xxxxxxx> Date: Thu, 20 Jan 2000 08:56:05 +0100 |
I thought this was a rather good article on XPath, by Norman Walsh: http://www.arbortext.com/Think_Tank/Norm_s_Column/Issue_One/issue_one.html Linda -----Original Message----- From: Philip Borenstein [mailto:pb@xxxxxxxxxx] Sent: Wednesday, January 19, 2000 7:35 PM To: 'xsl-list@xxxxxxxxxxxxxxxx' Subject: Making balanced two-column tables from one-column data 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: <TASKS> <TASK> <COMPONENTS> <COMPONENT>A</COMPONENT> <COMPONENT>B</COMPONENT> <COMPONENT>C</COMPONENT> <COMPONENT>D</COMPONENT> <COMPONENT>E</COMPONENT> <COMPONENT>F</COMPONENT> <COMPONENT>G</COMPONENT> <COMPONENT>H</COMPONENT> <COMPONENT>I</COMPONENT> <COMPONENT>J</COMPONENT> <COMPONENT>K</COMPONENT> </COMPONENTS> </TASK> </TASKS> I want to produce a two-column table like this: A G B H C I D J E K F (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> <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. --philip borenstein. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Making balanced two-column tabl, Mike Brown | Thread | displaying an html non-breaking spa, swright |
Parameters to stylesheets in the br, Jon Smirl | Date | problem with the xsl:attribute and , Didier PH Martin |
Month |