RE: [xsl] Grouping by shift problem

Subject: RE: [xsl] Grouping by shift problem
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Fri, 9 Sep 2005 10:25:25 +0300
Hi,

If $shift and $departs are bound to corresponding elements, then

  <xsl:template match="shifts">
    <alldeparts>
      <xsl:for-each select="*">
        <xsl:variable name="start" select="translate(@start, ':', '')"/>
        <xsl:variable name="end">
          <xsl:choose>
            <xsl:when test="@end = '00:00:00'">240000</xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="number(translate(@end, ':', ''))"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:copy>
          <xsl:copy-of select="@*"/>
          <xsl:for-each select="$departs/door">
            <xsl:variable name="time" select="translate(substring-after(time,
'T'), ':', '')"/>
            <xsl:if test="$time &gt;= $start and $time &lt; $end">
              <depart>
                <xsl:copy-of select="*"/>
              </depart>
            </xsl:if>
          </xsl:for-each>
        </xsl:copy>
      </xsl:for-each>
    </alldeparts>
  </xsl:template>

Removing shift1 from the results shouldn't be too difficult an excercise.

Cheers,

Jarno

--
Eryk Orpheus: Eryk Orpheus Live at Colours
<http://nuenergy.co.uk/new/musicEvents/djMixDetail.php?id=55>

> -----Original Message-----
> From: ext Kent Seegmiller [mailto:hookjaw20@xxxxxxxxxxx]
> Sent: 09 September, 2005 09:05
> To: XSLT
> Subject: [xsl] Grouping by shift problem
>
>
> I have a shift doc (shifts.xml):
>
> <shifts>
>     <shift1 start='00:00:00' end='08:00:00'/>
>     <shift2 start='08:00:00' end='16:00:00'/>
>     <shift3 start='16:00:00' end='00:00:00'/>
> </shifts>
>
> That I want as a lookup table
>
> Now I have anoher doc (departures.xml) with depart times and such:
>
> <departs>
>     <door>
>     <time>2005-06-12T15:02:06</time>
>     <name>Joe Somebody</name>
>     <dock>032</dock>
>     </door>
>     <door>
>     <time>2005-06-13T17:03:56</time>
>     <name>Joe Somebodyelse</name>
>     <dock>055</dock>
>     </door>
>     ...
> </departs>
>
> How do I group the <time> elements by shift?
>
> like thus,
> <alldeparts>
> <shift2>
>     <depart>
>     <name>Joe Somebody</name>
>     <time>2005-06-13T17:03:56</time>
>     <dock>055</dock>
>     </depart>
> ...
> </shift2>
> <shift3>
>     <depart>
>     <time>2005-06-13T17:03:56</time>
>     <name>Joe Somebodyelse</name>
>     <dock>055</dock>
>     </depart>
> ...
> </shift3>
> ...
> </alldeparts>
> etc.
>
> Thanks in advance, Kent

Current Thread