cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT - Current Date

itabhishek9
Participant
0 Kudos


Hi SDNites,

I am trying to get the current date in XSLT 1.0. Please let me know how should I do it. There are certain blogs which mentions that I have to write JAVA code and import it into XSLT. If this is the way can you please suggest how should I import JAVA code into XSLT.

Also there are certain blogs which says that XSLT 2.0 has methods which does that. Can you please let me know how do I move from version 1.0 to 2.0. I am using NWDS to write my XSL transformation logic and it has automatically used version 1.0.

 

<xsl:stylesheet version="1.0"

Regards,

Abhi

Accepted Solutions (0)

Answers (2)

Answers (2)

RaghuVamseedhar
Active Contributor
0 Kudos

Abhishek,

Use XSLT 2.0 in PI.

FYI, you can set new processor in NWDS "Processor Tab".

Help - Eclipse Platform

nabendu_sen
Active Contributor
0 Kudos

Hi Abhishek,

You can use multiple mapping in your ESR - Operation Mapping to achieve this requirement.

In your 1st Message Mapping, use the Sender Message Type as your Source as well as Target. Then populate current date from UDF function 'currentDate' and pass it to a non used field of Sender structure.

In the 2nd Mapping which is XSLT, use this field value to populate actual Target field of the Receiver structure.

Regards,

Nabendu.

Former Member
0 Kudos

You could use something like this (months in GregorianCalendar are 0 based)

This template calls Java class GregorianCalendar


<xsl:template name="today"  xmlns:cal="java:java.util.GregorianCalendar">

  <xsl:variable name="rightNow" select="cal:getInstance()" />

  <xsl:variable name="month" select="cal:get($rightNow, 2) + 1" />

  <xsl:variable name="day" select="cal:get($rightNow, 5)" />

  <xsl:variable name="year" select="cal:get($rightNow, 1)" />

  <xsl:value-of

   select="$year" />-<xsl:value-of select="$month" />-<xsl:value-of select="$day" />

</xsl:template>

br

itabhishek9
Participant
0 Kudos

Thanks for the reponse Nabendu.

Above mentioned suggstion will work. Can you please suggest if the same can be achived via using XSLT mapping only (Idea to to improve the performance by avoiding multiple mappings).

Regards,

Abhi

nabendu_sen
Active Contributor
0 Kudos

Hi Abhishek,

Performance wise I really don't think you are going to face any issue. Unfortunately XSLT 1.0 does not have any Standard Function to retrieve Current Date.

You can check below document for SAP PI / PO support of XSLT 2.0

Regards,

Nabendu.