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

Making sorted balanced two-column tables from one-column dat

Subject: Making sorted balanced two-column tables from one-column data from unsorted data
From: Tom Chmielenski <Tom.Chmielenski@xxxxxxxxxxx>
Date: Wed, 26 Jul 2000 17:10:19 -0400
xsl two column sorted table
I am trying to create a two column table from unsorted data.
The idea is very similar to the XSL FAQ: Making balanced two-column tables
from one-column data (see
http://www.dpawson.freeserve.co.uk/xsl/N7450.html#N13669 ).  However, my
data is initially unsorted.  
I initially tried adding  <xsl:sort> as a subelement to <xsl:for-each>, and
I get the following results (using MSXML3):

	A H
	B E
	C G
	D K
	E J
	F

The first column is sorted and is correct, the second column is not.  Looks
like  "select=$comp-list[$here+$half]" is using the unsorted list of
COMPONENTS rather than the sorted list.  This kinda makes sense.  

So I tried to create a variable that contains the sorted list of nodes like
this, but this yields no nodes:
	  <xsl:variable name="sorted-comp-list">
  		<xsl:for-each select="COMPONENT">
			<xsl:sort select="." />
		</xsl:for-each>
	  </xsl:variable>

Anybody know of a way to create a sorted list of nodes and be able store in
a variable for later use?

Thanks in advance.
<Tom/>


==================
Source is attached below.
==================
<!-- tabletest.xml  -->
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="tabletest.xsl"?>
<TASKS>
  <TASK>
    <COMPONENTS>
	<!-- same data as FAQ, but not in alpha order -->
      <COMPONENT>F</COMPONENT>
      <COMPONENT>B</COMPONENT>
      <COMPONENT>I</COMPONENT>
      <COMPONENT>C</COMPONENT>
      <COMPONENT>A</COMPONENT>
      <COMPONENT>D</COMPONENT>
      <COMPONENT>H</COMPONENT>
      <COMPONENT>E</COMPONENT>
      <COMPONENT>G</COMPONENT>
      <COMPONENT>K</COMPONENT>
      <COMPONENT>J</COMPONENT>
    </COMPONENTS>
  </TASK>
</TASKS>

<!-- tabletest.xsl  -->
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" indent="yes"/>

<xsl:template match="/">

  <xsl:apply-templates/>
</xsl:template>
<xsl:template match="TASKS/TASK/COMPONENTS">
  <xsl:variable name="t-size" select="count(COMPONENT)"/>
  <xsl:variable name="half" select="ceiling($t-size div 2)"/>
   
  <xsl:variable name="comp-list" select="COMPONENT"/>

<TABLE>
  <xsl:for-each select="$comp-list" >
  	<xsl:sort select="."/>
	<xsl:variable name="here" select="position()"/>

	<xsl:if test="$here &lt; $half+1">
   	<TR>
   		<TD><xsl:value-of select="."/></TD>
   		<TD>
       		<xsl:choose>
  				<xsl:when test="$comp-list[$here+$half]">
    				<xsl:value-of
select="$comp-list[$here+$half]"/>
       			</xsl:when>
       			<xsl:otherwise></xsl:otherwise>
       		</xsl:choose>
      	</TD>
   	 </TR>
	 </xsl:if>
  </xsl:for-each>
</TABLE>

</xsl:template>
</xsl:stylesheet>


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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