Re: a new(?) grouping problem

Subject: Re: a new(?) grouping problem
From: "Nikolai Grigoriev" <grig@xxxxxxxxxxx>
Date: Thu, 29 Jun 2000 17:22:17 +0400
Mike Brown wrote:

> I want to group consecutive days with the same hours together, and just
> print the first and last day in each group.
> I also want to ignore the 'Holidays' day. I put it in there because I
> can't use a solution that assumes Sunday's hours aren't followed by
> something that could be the same.

This can be achieved by recursion: you call a template recursively until there's
no more following-siblings that have the same text (passed as a param), like in
the stylesheet below:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=""; version="1.0">

<xsl:output method="html" version="4.0"/>

<!-- Root template: just create a table. -->
<xsl:template match="Hours">

<!-- Exclude holidays from processing -->
<xsl:template match="Holidays" priority="2"/>

<!-- Single days, except for holidays. -->
<!-- A modeless template creates the row -->
<xsl:template match="Hours/*">
  <xsl:variable name="hours" select="text()"/>

        <xsl:value-of select="name()"/>
        <xsl:apply-templates mode="end"
          <xsl:with-param name="hours" select="$hours"/>
      <td><xsl:value-of select="."/></td>

<!-- A day closes the period if there's no better candidate -->
<xsl:template match="Hours/*" mode="end">
  <xsl:param name="hours"/>

  <xsl:if test="text()=$hours">
        <xsl:apply-templates mode="end"
          <xsl:with-param name="hours" select="$hours"/>
        <xsl:text> - </xsl:text><xsl:value-of select="name()"/>



 XSL-List info and archive:

Current Thread