cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT Mapping - Getting current date in XSLT version 1.0

Former Member
0 Kudos

Hi,

I want to fetch the system date and compare it with another date, say 06.04.2010.

How can I do this in XSLT 1.0?

Thanks & Regards,

Aditi Naik

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Jude,

Thank you for the quick response. Can you please tell me how I can use syst-datum in an xslt code to fetch the actual date value?

I need to use this XSLT mapping in XI. I had created a mapping in XSLT 2.0 with the date check as follows:

<xsl:when test="boolean(//*[local-name() = 'IRenvelope']/node() and boolean(year-from-date(current-date()) = 2009) and boolean(month-from-date(current-date()) &gt; 11) and boolean(day-from-date(current-date()) &gt; 05))">

However, the currentdate() function is not supported by XI. Hence I need to replace code given above by using statements that

are supported in XSLT 1.0

Thanks & Regards,

Aditi Naik

former_member187339
Active Contributor
0 Kudos

Hi Aditi,

(As far as I know) There is no standard way in XSLT 1.0 to take the system date .. You cah use XSLT with java enhancement to get the system date. check this

http://help.sap.com/saphelp_nwpi71/helpdata/EN/55/7ef3003fc411d6b1f700508b5d5211/frameset.htm

Also for comparing two date strings you can use something like

<xsl:if test="number(translate(date1, '-', '')) > number(translate(date2,'-', ''))">

Check if this works

Regards

Suraj

Former Member
0 Kudos

Hi,

I tried using the following code:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cal="java:java.util.GregorianCalendar">

<xsl:output method="xml"/>

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

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

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

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

<xsl:variable name="year" select="substring(string(cal:get($now, 1)), 3, 2)"/>

</xsl:template>

..........

.........

..............

<Body>

<xsl:choose>

<xsl:when test="boolean(//*[local-name() = 'IRenvelope']/node()) and boolean($year = 2009) and boolean($month &gt; 11) and boolean($day &gt; 05))">

................

..........

.........

</xsl:when>

..............

..........

...........

</xsl:choose>

</Body>

However, when I try to run this mapping I get the error "Invalid XPath Expression" in Altova.

Can you please tell me exactly what is wrong with this code and how I can get around this?

Thanks & Regards,

Aditi Naik

Former Member
0 Kudos

Hi,

I also tried using the following code:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="java:java.util.GregorianCalendar">

<xsl:output method="xml"/>

<xsl:variable name="now" select="date:get()"/>

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

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

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

<xsl:variable name="day1" select="$day"/>

<xsl:variable name="month1" select="$month"/>

<xsl:variable name="year1" select="$year"/>

...........

.........

.........

</xsl:stylesheet>

I get the error that function date:get() is not in correct namespace.

I'm using Altova XML Spy and wrote the code above by referring to the format given on the Altova site

http://www.altova.com/manual/AltovaXML/index.html?xextjava.htm

Could you please tell me how I can proceed further?

Thanks & Regards,

Aditi Naik

former_member200962
Active Contributor
0 Kudos

Check this thread on how to get current date in XSLT 1.0:

Regards,

Abhishek.

Former Member
0 Kudos

Hi ,

You can use syst-datum in the table SYST.

Once you fetch the value you can compare it easily

Regards,

Jude