Subject: RE: [xsl] Building a 2 Column HTML Table From: "McNally, David" <David.McNally@xxxxxxxxxx> Date: Wed, 6 Mar 2002 11:29:45 -0500 |
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 ) < $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) < (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@xxxxxxxxxx (212) 553-7475 > -----Original Message----- > From: Champion, Ritchie [mailto:Ritchie.Champion@xxxxxx] > Sent: Monday, March 04, 2002 5:29 PM > To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx' > 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@xxxxxx > > > 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Building a 2 Column HTML Tabl, Champion, Ritchie | Thread | [xsl] include statement, Kevin . Gutch |
RE: [xsl] XPath perfomance in attri, Michael Kay | Date | RE: [xsl] RFC XSLT Standard - "Furt, naha |
Month |