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

Re: grouping, sorting, splitting

Subject: Re: grouping, sorting, splitting
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Mon, 18 Apr 2005 04:37:19 -0700 (PDT)
xsl param sort date
Hi Stephen,
  Please try this 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:key name="by-date" match="entry" use="@date" />
  
<xsl:template match="/page">
    <html>
      <head>
        <title/>
      </head>
      <body>
        <table>
          <xsl:for-each select="entry[generate-id() =
generate-id(key('by-date', @date)[1])]">
            <xsl:for-each select="key('by-date',
@date)">
              <xsl:sort select="title" />
              <xsl:if test="(position() = 1) or
((position() - 1) mod 3 = 0)">
                <xsl:variable name="pos"
select="position()" />
                <tr>
                  <xsl:call-template
name="generateTRs">
                    <xsl:with-param name="node-set"
select="key('by-date', @date)[position() &gt;=
$pos][position() &lt;= ($pos + 3)]" />
                  </xsl:call-template>
                </tr>
              </xsl:if>
            </xsl:for-each>
            <!-- a dummy row -->
            <tr>
              <td>-</td><td>-</td><td>-</td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>  
</xsl:template>
  
<xsl:template name="generateTRs">
    <xsl:param name="node-set" />
    
    <tr>
      <xsl:for-each select="$node-set">
        <td>
          <xsl:value-of select="@date" />
        </td>
      </xsl:for-each> 
      <xsl:call-template name="generateRemainingTDs">
         <xsl:with-param name="n" select="3 -
count($node-set)" />
      </xsl:call-template>
    </tr>  
</xsl:template>
  
<xsl:template name="generateRemainingTDs">
    <xsl:param name="n" />
        
    <xsl:if test="$n &gt; 0">
      <td/>
      <xsl:call-template name="generateRemainingTDs">
        <xsl:with-param name="n" select="$n - 1" />
      </xsl:call-template>
    </xsl:if>
</xsl:template>
  
</xsl:stylesheet>

Regards,
Mukul

--- beowulf <carisenda@xxxxxxxxx> wrote:
> Hi,
> 
> I have XML if the form:
> 
> <page>
> <entry date="2005-04-15">
>  <title>foo</title>
> </entry>
> <entry date="2005-04-15">
>  <title>bar</title>
> </entry>
> <entry date="2005-02-05">
>  <title>baz</title>
> </entry>
> ...
> </page>
> 
> Which I am trying to group by date, sort by tiltle
> and then split into
> sets of 3, 3 being the number of columns in the HTML
> TABLE element I
> am trying to produce as an end result.
> 
> I've got the grouping and sorting:
> <xsl:for-each select="entry[key('days', @date) and
> count(.|key('days',
> @date)[1])= 1]">
> <xsl:sort select="title"/>
> 
> and I've even got the first item in each group of
> three from that
> grouped and sorted set:
> <xsl:for-each select="key('days', @date)[position()
> mod 3 = 1]">
> 
> But I just can't seem to make the final leap to
> displaying the
> following siblings of the above, making the 3 cell
> rows. Should I be
> doing this some other way or can someone help me
> where I am?
> 
> Many thanks,
> Stephen
> 
> 


		
__________________________________ 
Do you Yahoo!? 
Plan great trips with Yahoo! Travel: Now over 17,000 guides!
http://travel.yahoo.com/p-travelguide

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.