Solved

Date in XSLT mapping

Posted on 2014-09-16
12
238 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 80

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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP delete contents of file- before writing to it 6 50
Need a modeling tool 2 43
ASP and Looping Thru a XML Document 4 33
C# XML Get Values 4 37
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
A short article about problems I had with the new location API and permissions in Marshmallow
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 …

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