Solved

Date in XSLT mapping

Posted on 2014-09-16
12
212 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 78

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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

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

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.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

18 Experts available now in Live!

Get 1:1 Help Now