Hi
This is probably not the right language to use to describe what I want
to do, but I am not that familiar with java (or for that matter xslt),
so please bear with me.
We are making calls to java in xml (using cocoon) and I am working on a
generic template to get the current date, add an offset to it and then
get the value-of the date in a specified format. Here is the code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xslt/java"
xmlns:cal="java.util.Calendar"
xmlns:sf="java.text.SimpleDateFormat"
exclude-result-prefixes="java"
>
<!--
Gets current date + offset in form ddMMMyy
Params: offset days to add to current date
-->
<xsl:template name="offset_date_ddMMMyy">
<xsl:param name="offset">
<xsl:variable name="today" select="cal:getInstance()"/>
<xsl:variable name="todayPlus" select="cal:add($today, 6, $offset)"/>
<xsl:value-of select="java:format(sf:new('ddMMMyy'),
cal:getTime($today))"/>
</xsl:template>
<!--
Gets current date in form MM/dd/yyyy
-->
<xsl:template name="offset_date_MMddyyyy">
<xsl:variable name="today" select="cal:getInstance()"/>
<xsl:variable name="todayPlus" select="cal:add($today, 6, $offset)"/>
<xsl:value-of select="java:format(sf:new('MM/dd/yyyy'),
cal:getTime($today))"/>
</xsl:template>
</xsl:stylesheet>
Now, what bothers me about this is the variable todayPlus which serves
no purpose other than giving us an opportunity to call add. How can we
avoid this useless call?
Cheers.
Kamal.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--