You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Mi...@telia.fi on 2001/03/21 10:51:08 UTC

Xalan Extensions


I have problems with my first extension for Xalan-Java 1

I wrote a simple java class that uses the SimpleDateFormat-class. It has
only one method that returns the formated date as a String.

My XSL-stylesheet should just call the method and return it  in a
xsl:variable. I looked at the examples on the xalan home page, but I just
don't get it. Where do I create an instance of my class? How do I call a
method?

Thanks for any help!


**************************************************************
package util;

import java.util.*;
import java.text.*;

public class FinnishDate
{
  SimpleDateFormat finnishFormat = new
SimpleDateFormat("EEEE dd.MM.yyyy", new Locale("FI",
"FI"));

  public String getFinnishDate()
  {
    Date now = new Date();
    String finnishDate = finnishFormat.format(now);
    return finnishDate;
  }
}
*************************************
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"

xmlns:java="http://xml.apache.org/xslt/java" >

<xsl:variable name="fd"
select="java:util.FinnishDate.new()"/>

<xsl:template match="/">
 <html>
 <body>
 <p>
 <xsl:value-of select="date:getFinnishDate($fd)"/>
 </p>
 </body>
 </html>
</xsl:template>

</xsl:stylesheet>





Re: Xalan Extensions

Posted by Gary L Peskin <ga...@firstech.com>.
Mika.Borner@telia.fi wrote:
> 
> I have problems with my first extension for Xalan-Java 1

You should really upgrade to XalanJ2.  XalanJ1 is going away.

> 
> I wrote a simple java class that uses the SimpleDateFormat-class. It has
> only one method that returns the formated date as a String.
> 
> My XSL-stylesheet should just call the method and return it  in a
> xsl:variable. I looked at the examples on the xalan home page, but I just
> don't get it. Where do I create an instance of my class? How do I call a
> method?

Use the java: prefix on your xsl:value-of element.  You do not have
date: namespace prefix defined.  Your .new call created a new instance
of the class.

Gary