[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

XSLT to decrement a Text TimeDate field by 1 hour

Posted on 2011-09-19
9
Medium Priority
?
547 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

649 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