Solved

XSLT to decrement a Text TimeDate field by 1 hour

Posted on 2011-09-19
9
496 Views
Last Modified: 2012-05-12
Hello

I am looking for an XSLT function that will take this field:  <CHANGEDATE>2011-09-19T20:07:54+01:00</CHANGEDATE>

and replace it with <CHANGEDATE>2011-09-19T19:07:54+01:00</CHANGEDATE>

It needs to be smart enough to handle the midnight hour where the date will need to be modified also.

0
Comment
Question by:erlythornton
  • 7
  • 2
9 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36564993
if you have to use XSLT1

http://www.exslt.org/date/functions/add/index.html

lists the processors that support this function
if your processor is none of those, you can import the template Jeni Tennison developed:
- import it (preferably make a local copy)
- declare the namespace
- call the template date:add with CHANGEDATE as the first with-param (I think you need to cut of the part of the timezone) and "-PT1H" as the value for the second with-param

if you could use XSLT2, it is a s simple as
<xsl:value-of select="xs:date(CHANGEDATE) - 'PT1H'"/>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36565082
hmm for XSLT2 we need more explicit casting
        <xsl:value-of select="xs:dateTime(CHANGEDATE) - xs:dayTimeDuration('PT1H')"/>
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 36565105
no timezone cutting required in XSLT1

it is nicer to use the extension functions, when available in your processor
but the following always works
PLEASE, copy the exslt xsl file to a local location and import from there
to avoid frequent access to the exslt server
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="date"
    xmlns:date="http://exslt.org/dates-and-times"
    version="1.0">
    <xsl:import href="http://www.exslt.org/date/functions/add/date.add.template.xsl"/>
    <!-- make this <xsl:import href="date.add.template.xsl"/> -->
    <xsl:template match="/">
        <xsl:call-template name="date:add">
            <xsl:with-param name="date-time" select="CHANGEDATE" />
            <xsl:with-param name="duration" select="'-PT1H'" />
        </xsl:call-template>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36565108
took this as an example

<?xml version="1.0" encoding="UTF-8"?>
<CHANGEDATE>2011-09-19T00:07:54+01:00</CHANGEDATE>
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36565112
by the way, as soon as you are involved in dateand time processing, it is definitely worth migrating to XSLT2
0
 

Author Comment

by:erlythornton
ID: 36568803
This works great in XML Cooktop.  My application unfortunately only supports XSLT1 so I am using that solution.  I am not at a place where I can test inside the application to make sure it has no problems, but as soon as I can I will confirm your solution.
0
 

Author Comment

by:erlythornton
ID: 36575814
My app is on a closed network so cannot access the exslt org site.  So I copied the template into my stylesheet directly and referenced it there.  It still failed with some stack overflow error when I tried to invoke the call template.  When you said to copy it locally did you just mean to copy it to an internal or local web site and change the import statement to reflect the correct path?  What about the exslt.org namespace URL?  Is there a way to handle that?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36576171
just copy the xslt with the template to a local path and import it using the local path
(preferably just put it next to your XSLT and add the correct filename in teh import statement, without a path)

the exslt.org namespace does not imply that you need access, it is just a unique string
people often mistake a URI for a URL because for practical reasons the syntax is similar
a namespace is a URI, so nothing more than a string typed identifier

As long as you have a decent XSLT processor, this should work without issues in a closed environment
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36576459
welcome
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 69
Fixed div within Bootstrap carousel item 11 54
MS Access XML Export Query Setup Multiple Tag Values 15 28
Advice on Xojo as a development tool over VB. 4 31
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now