cancel
Showing results for 
Search instead for 
Did you mean: 

xslt mapping can't get date from java

Former Member
0 Kudos

I am trying to get the current date/time from java in my xsl mapping. I can't seem to get it to work. This is the code I am using in my xsl file.

<IDField>

<xsl:template name="currentTime" xmlns:date="java:java.util.Date">

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

</xsl:template>

</IDField>

also tried

<xsl:value-of select="java:java.util.Date:new()"/>

I simply want to put the current date time in the IDField. What am I doing wrong? I am currently getting back a xslt mapping error. Here's the error....

Transformer configuration exception occurred when loading XSLT

I've tried a few different ways, but none have worked. What I'm looking for is the specific code that would display the date/time.

- Emmett

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I figured it out. The main problem was that I didn't have the following in this line....

<xsl:stylesheet version="1.0" <b>xmlns:java="http://xml.apache.org/xslt/java" </b>xmlns:xsl="http://www.w3.org/1999/XSL/Transform" .....>

Once I included xmlns:java="http://xml.apache.org/xslt/java" all the java functions were available. I also found the great date template. In case anyone wants to check it out here it is...

<xsl:template name="today"

xmlns:cal="xalan://java.util.GregorianCalendar">

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

<!-- The GregorianCalendar class counts months from zero

so we have to add one to get the customary number -->

<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>

I found this template here...

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

- Emmett