Solved

Date in XSLT mapping

Posted on 2014-09-16
12
226 Views
Last Modified: 2014-12-07
Hi Folks,

I am trying to implement current date in XSLT mapping. Also my criteria is to add additional number of days to the date.

I currently Have the following which gives me the current date, Please let me know how can I modify it to add say 60 days to it, eg., if the current date is 20140916, it should give 20141115

<EXXXX><xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('yyyyMMdd'), java:java.util.Date.new())" /></EXXXX>
0
Comment
Question by:kalyangkm
  • 8
  • 2
12 Comments
 

Author Comment

by:kalyangkm
ID: 40327217
Also I am using XSLT 1.0
0
 
LVL 79

Expert Comment

by:David Johnson, CD, MVP
ID: 40327672
you're also using java
most languages allow you to add days
<EXXXX><xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('yyyyMMdd'),
ava:java.util.Date.new(),60)" /></EXXXX>
0
 

Author Comment

by:kalyangkm
ID: 40328092
Hi David,

Its not working, I don't think its allowing days like this. It throws an exception, and sorry I dont have any proper tool to catch exception as I am using a middleware tool which just says style sheet throws exception
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 37

Expert Comment

by:Gerwin Jansen
ID: 40328396
Not exacly my expertise but there is a small typo in David's example:

<EXXXX><xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('yyyyMMdd'),
java:java.util.Date.new(),60)" /></EXXXX>

(missing j at beginning of 2nd line)
0
 

Author Comment

by:kalyangkm
ID: 40328482
Gerwin,

It's not J, I have it right in my code. I think it's the addition of days at the end as one parameter is what is the problem
0
 

Author Comment

by:kalyangkm
ID: 40328643
Any more thoughts?
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 40328654
Not on my side, no.
0
 

Author Comment

by:kalyangkm
ID: 40328840
I am trying to use a java extension in XSLT as it looks like its not that simple in XSLT 1.0. But I am getting some syntax errors which I am not able to solve, could anyone help me out here.
For
c.setTime(new Date()); //todays date.

I am getting the following error
Syntax error on token "setTime", = expected after
       this token

Also I am getting the following error
Syntax error on token "(", < expected

for
c.add(Calendar.DATE, 90); // Adding 90 days


I am trying the following code

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.text.*;

public class DateAdd {
      
      
      SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
      Calendar c = Calendar.getInstance();
      c.setTime(new Date()); //todays date.
      c.add(Calendar.DATE, 90); // Adding 90 days
      String output = sdf.format(c.getTime());
      System.out.println(output);
0
 

Author Comment

by:kalyangkm
ID: 40328863
Please ignore my previous message, It was supposed to be in main method.
0
 

Accepted Solution

by:
kalyangkm earned 0 total points
ID: 40477842
I got the code working as below

package com.dateAdd;


import java.util.Calendar;
import java.util.Date;
import java.text.*;

public class DateAdd {
      
      public static String getDateadon(){
      //public static void main(String[] args){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            Calendar c = Calendar.getInstance();
            c.setTime(new Date()); // Now use today date.
            c.add(Calendar.DATE, 90); // Adding 90 days
            String output = sdf.format(c.getTime());
            return output;
            //System.out.println(output);      
      }
}
0
 

Author Closing Comment

by:kalyangkm
ID: 40485353
No one was providing any answer and I tried on my own and achieved it.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

815 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

11 Experts available now in Live!

Get 1:1 Help Now