Re: a new(?) grouping problem

Subject: Re: a new(?) grouping problem
From: Nick Browne <NickBrowne@xxxxxxxxxxxxxxx>
Date: Thu, 29 Jun 2000 12:18:36 +0100
Mike, try this to solve your grouping problem. It gives the answer you wanted based on the data given (which I
appreciate may not always the full solution). I'm sure you don't need my (verbose) comments but I'll leave
them in for my benefit !  :

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=""; version="1.0">
 <xsl:output method="html" version="4.0"/>

 <xsl:template match="/">

  <xsl:variable name="HoursData" select="/Hours/*[not(name()='Holidays')]"/>

   <xsl:for-each select="$HoursData[normalize-space() !=

      <xsl:value-of select="name()"/>
      <!-- if current day isn't Sunday, and next day's hours are
           the same as this day's, print hyphen -->
      <xsl:if test="name() != 'Sunday' and . =

      <!-- the question is, what goes here in place of foo? -->

      <xsl:call-template name="hours_chk">
       <xsl:with-param name="pos" select="1"/>

      <xsl:value-of select="."/>


 <!-- Using the (single) day element initially passed from the for-each as
      the context, work forward via recursion until a day is found
      that has a different 'hours' value and is not 'Holidays'          -->

 <xsl:template name="hours_chk">
  <xsl:param name="pos"/>

  <!-- Decide whether we need to keep searching ..          -->


   <!-- If there is still another following day with a value
        equal to the context value, call the template again and
        repeat the check for the next day                                                    -->

   <xsl:when test="(following-sibling::*[$pos]/text() = text() and
                    name(following-sibling::*[$pos]) != 'Holidays')">

    <xsl:call-template name="hours_chk">
     <xsl:with-param name="pos" select="$pos+1"/>


  <!-- Stop the search. If here, then we have found a day where the
       hours differed from the first in the group. Display the day name
       of the one before the failing one, i.e. display the last in the group -->

    <xsl:value-of select="name(following-sibling::*[$pos - 1])"/>


Nick Browne
Slipstone Ltd

 XSL-List info and archive:

Current Thread