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

RE: access java from xslt

Subject: RE: access java from xslt
From: "Ivan Pedruzzi" <ivan@xxxxxxxxxxxxxxx>
Date: Wed, 12 Dec 2001 12:53:18 -0500
import java in xsl

XT style

<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:IntDate="class:IntDate"   
		    version="1.0">
<xsl:output method="html"/>


<xsl:template match="/">
	<xsl:apply-templates select="/doc/date"/> 
</xsl:template>
<xsl:template match="date">
	<xsl:value-of select="IntDate:getDate(number(@year),
number(@month), number(@day), string(@format))"/><br/>
</xsl:template>
</xsl:stylesheet>

XML source

<?xml version="1.0"?>
<doc>
	<date year="1997" month="5" day="7" format="EEEE, MMMM dd (D),
yyyy z"/>
	<date year="1998" month="1" day="10" format="MMM d, yy"/>
	<date year="1999" month="2" day="5" format="EE, MMM dd, yyyy"/>
</doc>

Java source

import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;

public class IntDate
{
	public static Object getDate(double year, double month, double
day, String format)
	{
		// Date(int, int, int) has been deprecated, so use
Calendar to
		// set the year, month, and day.
		Calendar c = Calendar.getInstance();
		// Convert each argument to int.
		c.set((int)year,(int)month,(int)day);
		// create formatter
		SimpleDateFormat dateFormat = new
SimpleDateFormat(format);
		// perform formatting	
		return dateFormat.format(c.getTime());
	}
}

Ivan Pedruzzi
eXcelon Corporation
http://www.stylusstudio.com



> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Kevin.Gutch@xxxxxxxxxxx
> Sent: Wednesday, December 12, 2001 12:06 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  access java from xslt
> 
> 
> 
> I have seen the following example for accessing a Java  class 
> from inside XSLT.
> 
> <xsl:variable name="date"
>  select="Date:toString(Date:new())"
> xmlns:Date="http://www.jclark.com/xt/java/java.util.Date"/>
> 
> There also used to be an article on
> www.xml-zone.com/articles/vp0801/vp0801-1.asp   but it is no 
> longer there.
> The code seems relatively straight forward but I am having 
> the worst time trying to access an class that I have created. 
> Has anyone done this who could provide some guidance?
> 
> Thanks.
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.