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

Re: 3 level grouping

Subject: Re: 3 level grouping
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 08 Jun 2004 20:20:02 -0400
xcal xsl
At 2004-06-08 14:15 -0700, you wrote:
I am using the Meunchian method to group some
event calendar output. It is currently only grouped by
two levels, those being year and month. However, the
requirements have changed and I now need to group the
output by category, then year and then month.

I find any multi-level grouping is done more easily with variable-based grouping than by key-based grouping, because variables can scope what you are grouping while keys always work with document-wide scope.


I cannot figure out how to do this. Could someone lend a hand?

I hope the example below helps ... I only did simple text output, you can wrap that with whatever markup you need. You'll see how I set up variables with what has to be grouped, and then group only within those variables.


.................. Ken


T:\ftemp>type nathan.xml <obprcal:top xmlns="http://spaceresearch.nasa.gov/calendar" xmlns:obprcal="http://spaceresearch.nasa.gov/calendar" xmlns:xcal="http://www.ietf.org/internet-drafts/draft-ietf-calsch-many-xcal-01.txt"> <xcal:vcalendar xcal:version="2.0" xcal:prodid="-//nasa.gov/NONSGML Code U Extranet Calendar Service//EN" obprcal:category="Education Events" obprcal:timeperiod=""> <xcal:vevent> <obprcal:timeframe/> <obprcal:eventid>29</obprcal:eventid> <xcal:summary>A test future event.</xcal:summary> <xcal:location>Home</xcal:location> <xcal:categories>Education Events</xcal:categories> <xcal:dtstart>20040212</xcal:dtstart> <obprcal:dtstart_year>2004</obprcal:dtstart_year> <obprcal:dtstart_month>02</obprcal:dtstart_month> <obprcal:dtstart_day>12</obprcal:dtstart_day> <obprcal:dtstart_hour>00</obprcal:dtstart_hour> <obprcal:dtstart_minute>00</obprcal:dtstart_minute> <obprcal:dtstart_second>00</obprcal:dtstart_second> <xcal:dtend>20040212</xcal:dtend> <obprcal:dtend_year>2004</obprcal:dtend_year> <obprcal:dtend_month>02</obprcal:dtend_month> <obprcal:dtend_day>12</obprcal:dtend_day> <obprcal:dtend_hour>00</obprcal:dtend_hour> <obprcal:dtend_minute>00</obprcal:dtend_minute> <obprcal:dtend_second>00</obprcal:dtend_second> <xcal:url>url</xcal:url> </xcal:vevent> <xcal:vevent> <obprcal:timeframe/> <obprcal:eventid>27</obprcal:eventid> <xcal:summary>Education future</xcal:summary> <xcal:location>Your place</xcal:location> <xcal:categories>Education Events</xcal:categories> <xcal:dtstart>20040210T080000</xcal:dtstart> <obprcal:dtstart_year>2004</obprcal:dtstart_year> <obprcal:dtstart_month>02</obprcal:dtstart_month> <obprcal:dtstart_day>10</obprcal:dtstart_day> <obprcal:dtstart_hour>08</obprcal:dtstart_hour> <obprcal:dtstart_minute>00</obprcal:dtstart_minute> <obprcal:dtstart_second>00</obprcal:dtstart_second> <xcal:dtend>20040210T170000</xcal:dtend> <obprcal:dtend_year>2004</obprcal:dtend_year> <obprcal:dtend_month>02</obprcal:dtend_month> <obprcal:dtend_day>10</obprcal:dtend_day> <obprcal:dtend_hour>17</obprcal:dtend_hour> <obprcal:dtend_minute>00</obprcal:dtend_minute> <obprcal:dtend_second>00</obprcal:dtend_second> <xcal:url>url</xcal:url> </xcal:vevent> </xcal:vcalendar> <xcal:vcalendar xcal:version="2.0" xcal:prodid="-//nasa.gov/NONSGML Code U Extranet Calendar Service//EN" obprcal:category="General Interest" obprcal:timeperiod=""> <xcal:vevent> <obprcal:timeframe/> <obprcal:eventid>29</obprcal:eventid> <xcal:summary>A test future event.</xcal:summary> <xcal:location>Home</xcal:location> <xcal:categories>Education Events</xcal:categories> <xcal:dtstart>20040212</xcal:dtstart> <obprcal:dtstart_year>2004</obprcal:dtstart_year> <obprcal:dtstart_month>02</obprcal:dtstart_month> <obprcal:dtstart_day>12</obprcal:dtstart_day> <obprcal:dtstart_hour>00</obprcal:dtstart_hour> <obprcal:dtstart_minute>00</obprcal:dtstart_minute> <obprcal:dtstart_second>00</obprcal:dtstart_second> <xcal:dtend>20040212</xcal:dtend> <obprcal:dtend_year>2004</obprcal:dtend_year> <obprcal:dtend_month>02</obprcal:dtend_month> <obprcal:dtend_day>12</obprcal:dtend_day> <obprcal:dtend_hour>00</obprcal:dtend_hour> <obprcal:dtend_minute>00</obprcal:dtend_minute> <obprcal:dtend_second>00</obprcal:dtend_second> <xcal:url>url</xcal:url> </xcal:vevent> <xcal:vevent> <obprcal:timeframe/> <obprcal:eventid>27</obprcal:eventid> <xcal:summary>Education future</xcal:summary> <xcal:location>Your place</xcal:location> <xcal:categories>Education Events</xcal:categories> <xcal:dtstart>20040210T080000</xcal:dtstart> <obprcal:dtstart_year>2004</obprcal:dtstart_year> <obprcal:dtstart_month>02</obprcal:dtstart_month> <obprcal:dtstart_day>10</obprcal:dtstart_day> <obprcal:dtstart_hour>08</obprcal:dtstart_hour> <obprcal:dtstart_minute>00</obprcal:dtstart_minute> <obprcal:dtstart_second>00</obprcal:dtstart_second> <xcal:dtend>20040210T170000</xcal:dtend> <obprcal:dtend_year>2004</obprcal:dtend_year> <obprcal:dtend_month>02</obprcal:dtend_month> <obprcal:dtend_day>10</obprcal:dtend_day> <obprcal:dtend_hour>17</obprcal:dtend_hour> <obprcal:dtend_minute>00</obprcal:dtend_minute> <obprcal:dtend_second>00</obprcal:dtend_second> <xcal:url>url</xcal:url> </xcal:vevent> </xcal:vcalendar> </obprcal:top>

T:\ftemp>type nathan.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:obprcal="http://spaceresearch.nasa.gov/calendar"
xmlns:xcal="http://www.ietf.org/internet-drafts/draft-ietf-calsch-many-xcal-01.txt"
                version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:variable name="events" select="//xcal:vcalendar"/>
  <xsl:for-each select="$events">
    <xsl:if test="generate-id(.)=
          generate-id($events[@obprcal:category=current()/@obprcal:category])">
      <xsl:value-of select="@obprcal:category"/>
      <xsl:text>
</xsl:text>
      <xsl:variable name="cats"
                select="$events[@obprcal:category=current()/@obprcal:category]/
                        xcal:vevent"/>
      <xsl:for-each select="$cats">
        <xsl:if test="generate-id(.)=
      generate-id($cats[obprcal:dtstart_year=current()/obprcal:dtstart_year])">
          <xsl:text>  </xsl:text>
          <xsl:value-of select="obprcal:dtstart_year"/>
          <xsl:text>
</xsl:text>
          <xsl:variable name="years"
          select="$cats[obprcal:dtstart_year=current()/obprcal:dtstart_year]"/>
          <xsl:for-each select="$years">
            <xsl:if test="generate-id(.)=
   generate-id($years[obprcal:dtstart_month=current()/obprcal:dtstart_month])">
              <xsl:text>    </xsl:text>
              <xsl:value-of select="obprcal:dtstart_month"/>
              <xsl:text>
</xsl:text>
              <xsl:for-each
        select="$years[obprcal:dtstart_month=current()/obprcal:dtstart_month]">
                <xsl:text>      </xsl:text>
                <xsl:value-of select="obprcal:eventid"/>
                <xsl:text>
</xsl:text>
              </xsl:for-each>
            </xsl:if>
          </xsl:for-each>
        </xsl:if>
      </xsl:for-each>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>saxon nathan.xml nathan.xsl
Education Events
  2004
    02
      29
      27
General Interest
  2004
    02
      29
      27

T:\ftemp>rem Done!



--
Public courses: Spring 2004 world tour of hands-on XSL instruction
Next: 3-day XSLT/XPath; 2-day XSL-FO - Birmingham, UK June 14,2004

World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


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.