RE: [xsl] access java from xslt

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

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: [xsl] 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