Solved

XSLT to decrement a Text TimeDate field by 1 hour

Posted on 2011-09-19
9
522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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. 
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

687 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