cancel
Showing results for 
Search instead for 
Did you mean: 

Current date in xslt mapping

Former Member
0 Kudos

Hi,

I've tried to get the current date in my xslt mapping.

I've used the following xslt coding:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">

<xsl:template match="/">

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

</xsl:template>

</xsl:stylesheet>

In stylus studio everything is OK and i retrieve the current date.

When i import the xslt in the mapping tool and test the mapping i get the following error:

javax.xml.transform.TransformerException: com.sap.engine.lib.xml.util.NestedException: Function with name 'current-date' not found in context library. at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:251)

While directly using the current date functionality within the message mapping everything is OK too.

Does anyone know which date-functionality is used within the message mapping within the Integration Builder and/or wich mapping to be used in xslt for a working scenario?

Thnx in advance!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

<xsl:template name="currentTime" 
              xmlns:date="java:java.util.Date">
  <xsl:value-of select="date:new()"/>
</xsl:template>

Go through this document

http://cafeconleche.org/books/xmljava/chapters/ch17s03.html

This link is also having the same problem please check

Please reward points

Thanks

Vikranth

Answers (4)

Answers (4)

Former Member
0 Kudos

Ok thnx, these anwers where very helpfull for me to solve this problem.

I've awarded points for all your answers.

For anyone interested later on, I needed the date in my XSLT mapping in the following format ddMMMyy.

Finnally I used the following xslt to achieve this:

<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) + 1" />

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

<xsl:variable name="month">

<xsl:choose>

<xsl:when test="$month=1">Jan</xsl:when>

<xsl:when test="$month=2">Feb</xsl:when>

<xsl:when test="$month=3">Mar</xsl:when>

<xsl:when test="$month=4">Apr</xsl:when>

<xsl:when test="$month=5">May</xsl:when>

<xsl:when test="$month=6">Jun</xsl:when>

<xsl:when test="$month=7">Jul</xsl:when>

<xsl:when test="$month=8">Aug</xsl:when>

<xsl:when test="$month=9">Sep</xsl:when>

<xsl:when test="$month=10">Oct</xsl:when>

<xsl:when test="$month=11">Nov</xsl:when>

<xsl:when test="$month=12">Dec</xsl:when>

<xsl:otherwise>INVALID MONTH</xsl:otherwise>

</xsl:choose>

</xsl:variable>

<xsl:choose>

<xsl:when test="$day &lt; 10">

<xsl:value-of select="concat(concat(concat('0',$day), $month), $year)"/>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="concat(concat($day, $month), $year)"/>

</xsl:otherwise>

</xsl:choose>

</xsl:template>

Former Member
0 Kudos

Great... U r a good example of an SDN member who not just learns but shares as well.

Former Member
0 Kudos

Hi,

I tried using the code that you have given above. But I'm getting an 'Invalid Xpath Expression" error.

I have written 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>

Could you please tell me how I can get around this error?

Thanks & Regards,

Aditi Naik

Former Member
0 Kudos

Hi,

I tried using the code that you have given above. But I'm getting an 'Invalid Xpath Expression" error.

I have written 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>

Could you please tell me how I can get around this error?

Thanks & Regards,

Aditi Naik

Former Member
0 Kudos

use this date:date-time()

also have a look at this

http://www.w3.org/TR/xpath-functions/#func-current-dateTime

(or)

Better write the Java UDF and call it in the XSLT...Its even better

Former Member
0 Kudos

Hi

You are using an EXSLT function, the XSLT processor in XI is not supporting the functionality of date-time.

The other way of doing it is, if you are using XSLT 1.0 (which is the case with you) you will have to use a java extension. Else if you are using XSLT 2.0 then you can use the current-date() function available in the same.

regards

Sameer

GabrielSagaya
Active Contributor
0 Kudos

<xsl:stylesheet

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

version="2.0">

<xsl:output method="xml"

indent="yes"

omit-xml-declaration="yes"/>

<xsl:template match="/aaa">

<xxx>

<xsl:value-of select="current-dateTime()"/>

</xxx>

<yyy>

<xsl:value-of select="current-date()"/>

</yyy>

<zzz>

<xsl:value-of select="current-time()"/>

</zzz>

</xsl:template>

</xsl:stylesheet>