Solved

XSLT to decrement a Text TimeDate field by 1 hour

Posted on 2011-09-19
9
492 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to count occurrences of each item in an array.

744 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

12 Experts available now in Live!

Get 1:1 Help Now