xsl datetime format with correct Timezone

Posted on 2005-05-03
Medium Priority
Last Modified: 2008-01-09
I am working with rss newsfeed and my xml data is something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type='text/xsl' href='rssfeed.xsl'?>
<rss version="2.0">
    <copyright>Copyright MHA</copyright>
    <generator>Webservice og DB</generator>
    <lastBuildDate>Tue, 03 May 2005 15:22:43 GMT</lastBuildDate>
      <pubDate>Sun, 24 Apr 2005 22:00:00 GMT</pubDate>
My rssfeed.xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <h2>My rss</h2>
    <table style="TABLE-LAYOUT: fixed" cellSpacing="0" cellPadding="0" width="100%" border="0" heihjt="100%">
      <tr bgcolor="#9acd32">
        <th align="left">News</th>        
      <xsl:for-each select="rss/channel/item">
      <xsl:variable name="articleid"><xsl:value-of select="link"/></xsl:variable>
      <a href="{$articleid}"><xsl:value-of select="title"/></a>
My question is how can I transform date and time format like this DD.MM.YYYY HH:mm:ss with a Norwegian Timezone(GMT+1) from the xml pubDate node.

Many thanks in advance!
Question by:michaenh
LVL 19

Accepted Solution

ramazanyich earned 500 total points
ID: 13922569
in standard XSLT 1.0 you can't work with date formats.
But many popular XSLT processors support exslt.com extensions and that extensions have some functions which support manipualtion with dates. check http://exslt.org/date/index.html 
Which XSLT processor do you use?

Author Comment

ID: 13924390
I use standard XSLT 1.0.
So it is not possible? .. hm.. well I will check out with http://exslt.org/date/index.html.

Added this to the .xsl file:
<xsl:variable name="day" select="substring-before(substring-after($date, ' '), ' ')"/>
<xsl:variable name="monthName" select="substring-before(substring-after(substring-after($date, ' '), ' '), ' ')"/>
<xsl:variable name="month" select="substring(substring-after('Jan01Feb02Mar03Apr04May05Jun06Jul07Aug08Sep09Oct10Nov11Dec12', $monthName), 1, 2)"/>
<xsl:variable name="year" select="substring-before(substring-after(substring-after(substring-after($date, ' '), ' '), ' '), ' ')"/>
<xsl:variable name="Time" select="substring-before(substring-after(substring-after(substring-after(substring-after($date,' '),' '),' '),' '),' ')"/>
<xsl:value-of select="concat($day,'.',$month, '.',$year,' ',$Time)"/>

 I will get:
24.04.2005 22:00:00, but it s not the correct Timezone.

I'll be back.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question