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

RE: RE: RE: RE: GMT to BST converter

Subject: RE: RE: RE: RE: GMT to BST converter
From: cknell@xxxxxxxxxx
Date: Fri, 15 Apr 2005 15:54:25 -0400
substring before edge
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:  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/

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.