Solved

XSLT to decrement a Text TimeDate field by 1 hour

Posted on 2011-09-19
9
512 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

730 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