This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Building a 2 Column HTML Table


I'm not sure I fully understand this, but I think you want to count the
number of documents in the list, find the middle document, then split the
columns at the end of the AlphaGroup that contains this middle document...

So I think something like this should work - I'm sort of selecting the
middle document, and using it to select and process its parent AlphaGroup
and all AlphaGroups that precede it, then selecting the first document
element that is first in an alpha group and is past the middle document, and
using it to select and process its parent AlphaGroup and all following
AlphaGroups:


<xsl:template match="/">
	<xsl:apply-templates select="//List"/>
</xsl:template>

<xsl:template match="List">
	<xsl:variable name="halfDocCount" select="count(AlphaGroup/document)
div 2"/>
	<p><xsl:value-of select="$halfDocCount"/></p>
	<table><tbody><tr valign="top">
		<td><!-- Column One -->
			<xsl:apply-templates
select="(AlphaGroup/document[count(../preceding-sibling::AlphaGroup/document
) &lt; $halfDocCount])[last()]" mode="doColumn1Groups"/>
		</td>
		<td><!-- Column Two -->
			<xsl:apply-templates
select="(AlphaGroup/document[not(preceding-sibling::document) and
count(../preceding-sibling::AlphaGroup/document) >= $halfDocCount])[1]"
mode="doColumn2Groups"/>
		</td>
	</tr></tbody></table>	
</xsl:template>

<xsl:template match="document" mode="doColumn1Groups">
	<xsl:apply-templates select=".. |
../preceding-sibling::AlphaGroup"/>
</xsl:template>

<xsl:template match="document" mode="doColumn2Groups">
	<xsl:apply-templates select=".. |
../following-sibling::AlphaGroup"/>
</xsl:template>

<xsl:template match="AlphaGroup">
	<ul><xsl:value-of select="letter"/>
		<xsl:apply-templates select="document"/>
	</ul>
</xsl:template>

<xsl:template match="document">
		<li><xsl:apply-templates select="filename"/></li>
</xsl:template>


Alternatively, here's a solution that uses keys (but is pretty similar to
the last one).  For simplicity I've assumed that there's only one List
element - if there were more than one, the key would have to be a bit more
complicated, probably involving the generate-id value of each List so that
the various AlphaGroups can be distinguished.  

Basically here, though, the key is a boolean - it gets value 1 for the
AlphaGroups up to and including the one with the middle document, and value
0 for the rest.

<xsl:key name="processSwitch" match="AlphaGroup"
use="number(count(preceding-sibling::AlphaGroup/document) &lt;
(count(..//document) div 2))"/>

<xsl:template match="/">
	<xsl:apply-templates select="//List"/>
</xsl:template>

<xsl:template match="List">
	<xsl:variable name="halfDocCount" select="count(AlphaGroup/document)
div 2"/>
	<p><xsl:value-of select="$halfDocCount"/></p>
	<table><tbody><tr valign="top">
		<td><!-- Column One -->
			<xsl:apply-templates select="key('processSwitch',
1)"/>
		</td>
		<td><!-- Column Two -->
			<xsl:apply-templates select="key('processSwitch',
0)"/>
		</td>
	</tr></tbody></table>	
</xsl:template>

<xsl:template match="AlphaGroup">
	<ul><xsl:value-of select="letter"/>
		<xsl:apply-templates select="document"/>
	</ul>
</xsl:template>

<xsl:template match="document">
		<li><xsl:apply-templates select="filename"/></li>
</xsl:template>

I'm not sure how efficient these two solutions are - but perhaps they'll
give you a starting point...

David.
--
David McNally            Moody's Investors Service
Software Engineer        99 Church St, NY NY 10007 
David.McNally@Moodys.com            (212) 553-7475 


> -----Original Message-----
> From: Champion, Ritchie [mailto:Ritchie.Champion@ps.net]
> Sent: Monday, March 04, 2002 5:29 PM
> To: 'XSL-List@lists.mulberrytech.com'
> Subject: [xsl] Building a 2 Column HTML Table
> 
> 
> I have an XML file of alphabetized links
> 
> 	<List>
> 		<listCount>25</listCount>
> 		<AlphaGroup>
> 			<letter>A</letter>
> 			<document>
> 				<title>A document title</title>
> 				<filename>document1.htm</filename>
> 			</document>
> 			<document>
> 				<title>A second document title</title>
> 				<filename>document2.htm</filename>
> 			</document>
> 			...possibly more documents
> 
> 		</AlphaGroup>
> 		<AlphaGroup>
> 			<letter>F</letter> ...
> 		</AlphaGroup>
> 
> 		.... more groups of alphabetized documents.
> 	
> 	</list>
> The XSLT file needs to transform the XML file into a html file with an
> indexed two column table of document links.  I am able to 
> produce a single
> column indexed table without any problems.  My problem is 
> that the split
> point of the 2 column list needs to be at the END of the 
> letter group which
> contains the middle link item.  The number of documents in 
> the XML file
> varies as does the number AlphaGroups.
> 
> Any help in how to solve this problem would be most appreciated.
> 
> Many thanks in advance.
> 
> Ritchie Champion
> Email: ritchie.champion@ps.net
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


---------------------------------------

The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission.  If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited.  If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments.  Thank you.

Every effort is made to keep our network free from viruses.  You should, however, review this e-mail message, as well as any attachment thereto, for viruses.  We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]