RE: RE: RE: RE: [xsl] GMT to BST converter

Subject: RE: RE: RE: RE: [xsl] GMT to BST converter
From: "tom tom" <tomxsllist@xxxxxxxxxxx>
Date: Mon, 18 Apr 2005 11:05:11 +0100
Thanks Charles, though as you have specific dates and times hardcoded I'm presuming that it's only good for this year?

From: cknell@xxxxxxxxxx
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: RE: RE: RE: [xsl] GMT to BST converter
Date: Fri, 15 Apr 2005 15:54:25 -0400

Thanks for pointing out my error. That makes sense. Here is the template I constructed. It has been lightly tested (most edge cases and the no-question cases). It has not been optimized. I image that it could be done more compactly and with fewer convenience variables. Although eliminating the convenience variables would make it much trickier to grasp, it would make the template more compact.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" indent="yes" encoding="UTF-8" />


  <xsl:param name="start-date" select="'23'" />
  <xsl:param name="end-date" select="'28'" />

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

<xsl:template match="Date">
<xsl:variable name="DOW" select="substring-before(., ', ')" />
<xsl:variable name="dm" select="substring-before(substring-after(.,', '),', ')" />
<xsl:variable name="M" select="substring-after($dm,' ')" />
<xsl:variable name="D" select="substring-before($dm,' ')" />
<xsl:variable name="h" select="substring-before(substring-after(substring-after(substring-after(.,$dm), ', '), ', '), ' GMT')" />
<xsl:variable name="y" select="substring-after(substring-before(., $h),$dm)" />
<xsl:variable name="Y" select="substring-before(substring-after($y, ', '), ',')" />
<xsl:variable name="shr" select="concat(number(substring-before($h, ':')) + 1, ':', substring-after($h, ':'))" />


<xsl:choose>
<xsl:when test="$M='October'" >
<xsl:choose>
<xsl:when test="$DOW = 'Sunday' and $D &gt; 24">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &lt; 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Monday' and $D &gt; 25">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &lt; 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Tuesday' and $D &gt; 26">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &lt; 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Wednesday' and $D &gt; 27">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &lt; 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Thursday' and $D &gt; 28">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &lt; 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Friday' and $D &gt; 29">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &lt; 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Saturday' and $D &gt; 30">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &lt; 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$M='March'" >
<xsl:choose>
<xsl:when test="$DOW = 'Sunday' and $D &gt; 24">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &gt;= 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Monday' and $D &gt; 25">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &gt;= 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Tuesday' and $D &gt; 26">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &gt;= 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Wednesday' and $D &gt; 27">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &gt;= 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Thursday' and $D &gt; 28">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &gt;= 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Friday' and $D &gt; 29">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &gt;= 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$DOW = 'Saturday' and $D &gt; 30">
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) &gt;= 1">
<Date><xsl:value-of select="concat($DOW, ', ', $D, ' ', $M, ', ',$Y, ', ', $shr, ' BST')" /></Date>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>


</xsl:stylesheet>
--
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Michael Kay <mike@xxxxxxxxxxxx>
Sent:     Fri, 15 Apr 2005 19:36:53 +0100
To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject:  RE: RE: RE: [xsl] GMT to BST converter


> > http://webexhibits.org/daylightsaving/b.html > > > > All the references I've found on the web (including the BBC) > > say that it (BST) begins and ends at 0100 hours. In the U.S. > > the time is 0200 so the issue of "Is it today or yesterday?" > > doesn't come up. > > > > > When the clock is turned back at the end of Summer Time, does > > > the time then become 00:00:01 of the same day or is it set > > > back to midnight of the previous day? > >

The reference above says that BST ends at 01:00 GMT, i.e. at 02:00 BST.

Michael Kay
http://www.saxonica.com/


_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger http://www.msn.co.uk/messenger


Current Thread