Solved

Date in XSLT mapping

Posted on 2014-09-16
12
241 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
[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
  • 8
  • 2
12 Comments
 

Author Comment

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

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

 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
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 38

Expert Comment

by:Gerwin Jansen, EE MVE
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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

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.
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 …
Progress
Starting up a Project

726 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