RE: [xsl] FW: XSL calling Java problem - urgent

Subject: RE: [xsl] FW: XSL calling Java problem - urgent
From: Manpreet Singh <singhm@xxxxxxxxxxx>
Date: Fri, 15 Oct 2004 10:35:19 +0530
Hi,

  Paste the following as indicated:

<?xml version="1.0"?>
<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0" 
xmlns:java="sample.HelloDate" 
exclude-result-prefixes="java">

<xsl:template match="/"> 
<xsl:variable name="date" select="'2004-12-20 01:01:01'"/>
<xsl:variable name="format" select="'dd/mm/yyyy'"/>

<p>Date: <xsl:value-of select="java:getDate($date, $format)"/></p>
</xsl:template>
</xsl:stylesheet>

Make an xsl file with above code.

package sample;
import java.text.SimpleDateFormat;
import java.sql.Timestamp;

public class HelloDate
{
public static String getDate(String inputDate, String dateFormat)
{
String outPutDate = "";
System.out.println("dateFormat " + dateFormat);

if ( inputDate != null && inputDate != "")
{
SimpleDateFormat patternDateTimeFormat = new
SimpleDateFormat ( dateFormat );
outPutDate = patternDateTimeFormat.format
(Timestamp.valueOf ( inputDate ) );
System.out.println(outPutDate);
}
else
{
outPutDate = "";
}
return outPutDate;
}
}

Make a java file with the above code and place it in a directory by the name
sample.

Place the xsl, a dummy xml with empty root tag and the directory sample
containing the class file for the above java file in same directory.
>From command prompt fire the following command:

C:\(Path till directory where the above described file and page are kept)>
java org.apache.xalan.xslt.Process -in XML_FILE -xsl XSL_FILE -out
OUTPUT_XML(just give a name with xml extension).

PS: Give the path of directory containing JDK in the CLASSPATH environment
variable if the above does not work.

Regards
Manpreet

Current Thread