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
Solved

Date in XSLT mapping

Posted on 2014-09-16
12
234 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

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

Suggested Solutions

Title # Comments Views Activity
Configure a Bean in an XML file 4 42
youtube blocking politics 4 55
XML extra information 8 29
Wordpress Cron - Send XML Data to external server FTP 3 21
A short article about a problem I had getting the GPS LocationListener working.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

809 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