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

RE: Complicated grouping and column question

Subject: RE: Complicated grouping and column question
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 29 Jun 2005 23:21:28 +0100
two column ul
Not directly relevant, but

                    <xsl:apply-templates
select="/schedule/division[substring(@name,1,1) = $current-letter]">

would be better written

<xsl:apply-templates select="current-group()"/>

I suspect your problem is an HTML problem not an XSLT one: as far as I can
tell you are trying to work out what HTML you want to generate, not what
XSLT you need to write to generate it. So this may not be the best list to
help you.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Will McCutchen [mailto:mccutchen@xxxxxxxxx] 
> Sent: 29 June 2005 21:56
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Complicated grouping and column question
> 
> Hi everyone,
> 
> I've got a problem trying to create two columns for an index of data. 
> I can't for the life of me figure out how to break the data over two
> columns.
> 
> This might be hard for me to explain, so please bear with me.
> 
> I've got a large XML file representing a course schedule for the
> community college where I work.  Here's a small sample of the format:
> 
> <schedule>
>     <division name="Business">
>         <cluster name="Ethics">
>             <course title="..." />
>             <course title="..." />
>             <course title="..." />
>         </cluster>
>         <cluster name="Accounting">
>             <course title="..." />
>         </cluster>
>     </division>
>     
>     <division name="Arts">
>         <cluster name="Painting">
>             <course title="..." />
>         </cluster>
>         <cluster name="Drawing">
>             <course title="..." />
>         </cluster>
>     </division>
> </schedule>
> 
> (The actual format is a little bit more complicated than that, but
> this is all of the structure that's involved in creating the index.)
> 
> I've got a stylesheet that creates a nice alphabetical index based on
> the schedule XML file.  For the sample above, the index would look
> like this:
> 
> A
> 	Arts
> 		Painting
> 		Drawing
> B
> 	Business
> 		Accounting
> 		Ethics
> 
> So, in the index, the top level is a letter from A-Z, the second level
> is a <division> name and the third level is a <cluster> name.
> 
> I'm using XSLT 2.0 and Saxon 8.4.  Here's the important part of the
> current stylesheet (which is just outputting a simple HTML unordered
> list, at the moment):
> 
> <xsl:template name="make-index">
> 	<ul>
>         <xsl:for-each-group select="/schedule/division"
> group-by="substring(@name,1,1)">
>             <xsl:sort select="current-grouping-key()" />
>             <xsl:variable name="current-letter"
> select="current-grouping-key()" />
>             
>             <li>
>                 <h2><xsl:value-of select="$current-letter" /></h2>
>                 <ul>
>                     <xsl:apply-templates
> select="/schedule/division[substring(@name,1,1) = $current-letter]">
>                         <xsl:sort select="@name" />
>                     </xsl:apply-templates>
>                 </ul>
>             </li>
>         </xsl:for-each-group>
>     </ul>
> </xsl:template>
> 
> <xsl:template match="division">
>     <li>
>         <xsl:value-of select="@name" />
>         <xsl:if test="cluster">
>             <ul>
>                 <xsl:apply-templates select="cluster">
>                     <xsl:sort select="@name" />
>                 </xsl:apply-templates>
>             </ul>
>         </xsl:if>
>     </li>
> </xsl:template>
> 
> <xsl:template match="cluster">
> 	<li><xsl:value-of select="@name" /></li>
> </xsl:template>
> 
> 
> Because I'm using for-each-group to break the divisions up into
> sections by their first letters, I just can't figure out how to
> calculate a good place to break the output into two columns.  The
> columns need to break on a letter, so the "C" section couldn't break
> at the bottom of one column and continue at the top of the other.  One
> other problem is that the index is weighted heavily towards the front
> of the alphabet, so the break will probably need to come around D or
> E.
> 
> If this post made any sense and anyone has any suggestions, I'll be
> grateful.  If I need to explain myself better, or provide a complete
> input document, I'd be glad to do so.
> 
> Thanks in advance for your help,
> 
> 
> Will.

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.