I have cleared up the problems I know about. Here is a tidier and shorter
version of the stylesheet with the template in question. I have modified the
stylesheet so I could test multiple inputs on a single run.
First my test input document:
<?xml version="1.0" encoding="UTF-8" ?>
<date-list>
<Date>Sunday, 27 March, 2005, 01:21 GMT</Date>
<Date>Sunday, 27 May, 2005, 01:21 GMT</Date>
<Date>Sunday, 27 October, 2005, 01:21 GMT</Date>
<Date>Sunday, 27 January, 2005, 01:21 GMT</Date>
<Date>Sunday, 27 June, 2005, 23:21 GMT</Date>
</date-list>
The output document:
<?xml version="1.0" encoding="UTF-8"?>
<date-list>
<Date>Sunday, 27 March, 2005, 2:21 BST</Date>
<Date>Sunday, 27 May, 2005, 2:21 BST</Date>
<Date>Sunday, 27 October, 2005, 01:21 GMT</Date>
<Date>Sunday, 27 January, 2005, 01:21 GMT</Date>
<Date>Monday, 28 June, 2005, 00:21 BST</Date>
</date-list>
The stylesheet:
<?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:strip-space elements="*" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="date-list">
<date-list>
<xsl:apply-templates />
</date-list>
</xsl:template>
<xsl:template match="Date">
<!-- Some convenience variables -->
<!-- Day of the Week (e.g., Sunday) -->
<xsl:variable name="DOW" select="substring-before(., ', ')" />
<!-- Date and month substring (e.g., 14 January) -->
<xsl:variable name="dm" select="substring-before(substring-after(.,', '),',
')" />
<!-- Month name (e.g., January) -->
<xsl:variable name="M" select="substring-after($dm,' ')" />
<!-- Day number (e.g., 14) -->
<xsl:variable name="D" select="substring-before($dm,' ')" />
<!-- Hour:Minutes -->
<xsl:variable name="h"
select="substring-before(substring-after(substring-after(substring-after(.,$dm), ', '), ', '), '
GMT')" />
<!-- Year with surrounding characters -->
<xsl:variable name="y" select="substring-after(substring-before(., $h),$dm)"
/>
<!-- Year stripped of surrounding characters -->
<xsl:variable name="Y" select="substring-before(substring-after($y, ', '),
',')" />
<xsl:variable name="BST-in-effect">
<xsl:choose>
<xsl:when test="$M = 'November' or $M = 'December' or $M = 'January' or $M =
'February'">False</xsl:when>
<xsl:when test="$M = 'April' or $M = 'May' or $M = 'June' or $M = 'July' or $M =
'August' or $M = 'September'">True</xsl:when>
<xsl:when test="$M = 'October'">
<xsl:choose>
<xsl:when test="$DOW = 'Sunday' and $D > 24">False</xsl:when>
<xsl:when test="$DOW = 'Monday' and $D > 25">False</xsl:when>
<xsl:when test="$DOW = 'Tuesday' and $D > 26">False</xsl:when>
<xsl:when test="$DOW = 'Wednesday' and $D > 27">False</xsl:when>
<xsl:when test="$DOW = 'Thursday' and $D > 28">False</xsl:when>
<xsl:when test="$DOW = 'Friday' and $D > 29">False</xsl:when>
<xsl:when test="$DOW = 'Saturday' and $D > 30">False</xsl:when>
<xsl:otherwise>True</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$M='March'">
<!-- Edge cases for changing to BST -->
<xsl:choose>
<xsl:when test="$DOW = 'Sunday' and $D > 24">True</xsl:when>
<xsl:when test="$DOW = 'Monday' and $D > 25">True</xsl:when>
<xsl:when test="$DOW = 'Tuesday' and $D > 26">True</xsl:when>
<xsl:when test="$DOW = 'Wednesday' and $D > 27">True</xsl:when>
<xsl:when test="$DOW = 'Thursday' and $D > 28">True</xsl:when>
<xsl:when test="$DOW = 'Friday' and $D > 29">True</xsl:when>
<xsl:when test="$DOW = 'Saturday' and $D > 30">True</xsl:when>
<xsl:otherwise>False</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$BST-in-effect = 'False'">
<xsl:copy-of select="." />
</xsl:when>
<xsl:otherwise>
<!-- BST is in effect. Adjustments to the day of week, date, month, and hour
may be necessary -->
<xsl:variable name="D-BST">
<!-- Check to see if the date must roll over -->
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) = 23">
<xsl:choose>
<!-- Cases where the roll-over brings the first day of the
subsequent month -->
<xsl:when test="$M = 'March' and $D = '31'">1</xsl:when>
<xsl:when test="$M = 'April' and $D = '30'">1</xsl:when>
<xsl:when test="$M = 'May' and $D = '31'">1</xsl:when>
<xsl:when test="$M = 'June' and $D = '30'">1</xsl:when>
<xsl:when test="$M = 'July' and $D = '31'">1</xsl:when>
<xsl:when test="$M = 'August' and $D = '31'">1</xsl:when>
<xsl:when test="$M = 'September' and $D = '30'">1</xsl:when>
<!-- Necessary only to add one to the current date -->
<xsl:otherwise><xsl:value-of select="number($D) + 1"
/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- No adjustment necessary -->
<xsl:otherwise><xsl:value-of select="$D" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="DOW-BST">
<!-- Check to see if the day of the week must roll over -->
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) = 23">
<xsl:choose>
<xsl:when test="$DOW = 'Sunday'">Monday</xsl:when>
<xsl:when test="$DOW = 'Monday'">Tuesday</xsl:when>
<xsl:when test="$DOW = 'Tuesday'">Wednesday</xsl:when>
<xsl:when test="$DOW = 'Wednesday'">Thursday</xsl:when>
<xsl:when test="$DOW = 'Thursday'">Friday</xsl:when>
<xsl:when test="$DOW = 'Friday'">Saturday</xsl:when>
<xsl:when test="$DOW = 'Saturday'">Sunday</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$DOW" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="H-BST">
<!-- Adjust the hour if necessary -->
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) = 23"><xsl:value-of
select="concat('00:', substring-after($h, ':'))" /></xsl:when>
<xsl:otherwise><xsl:value-of select="concat(number(substring-before($h, ':')) + 1,
':', substring-after($h, ':'))" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="M-BST">
<!-- Adjust the month if necessary -->
<xsl:choose>
<xsl:when test="number(substring-before($h, ':')) = 23">
<xsl:choose>
<xsl:when test="$M = 'March' and $D = '31'">April</xsl:when>
<xsl:when test="$M = 'April' and $D = '30'">May</xsl:when>
<xsl:when test="$M = 'May' and $D = '31'">June</xsl:when>
<xsl:when test="$M = 'June' and $D = '30'">July</xsl:when>
<xsl:when test="$M = 'July' and $D = '31'">August</xsl:when>
<xsl:when test="$M = 'August' and $D = '31'">September</xsl:when>
<xsl:when test="$M = 'September' and $D =
'30'">October</xsl:when>
<xsl:otherwise><xsl:value-of select="$M" /></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$M" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<Date><xsl:value-of select="$DOW-BST" />, <xsl:value-of select="concat($D-BST, ' ')" /> <xsl:value-of
select="$M-BST" />, <xsl:value-of select="$Y" />, <xsl:value-of select="$H-BST" /> BST</Date>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email
-----Original Message-----
From: cknell(_at_)onebox(_dot_)com
Sent: Mon, 18 Apr 2005 07:42:38 -0400
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: RE: RE: RE: RE: [xsl] GMT to BST converter
There are some omissions, one of which I have corrected (see the reply to Dave
Pawson), but there are no hard-coded specific dates and times. Please tell me
where you see them and I'll explain what I think they really are.
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email
-----Original Message-----
From: tom tom <tomxsllist(_at_)hotmail(_dot_)com>
Sent: Mon, 18 Apr 2005 11:05:11 +0100
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: RE: RE: RE: [xsl] GMT to BST converter
Thanks Charles, though as you have specific dates and times hardcoded I'm
presuming that it's only good for this year?
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--