[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Calling java in xsl.

Subject: Calling java in xsl.
From: Kamal Bhatt <kbhatt@xxxxxxxxx>
Date: Tue, 14 Feb 2006 14:54:41 +1100
java in xsl
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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.