list4xt : Mailing list for the XT users community.
[list4xt] Re: Extension mechanism question
Subject: [list4xt] Re: Extension mechanism question
From: Eric van der Vlist (vdv@dyomedea.com)
Date: 15/05/2000 - 18:26
Peter,
"Chen, PeterX" wrote:
>
> Does anyone know how to properly use the extension mechanism via XT?
There is a sample on XT's home page (http://jclark.com/xml/xt.html)
available in the XT distribution and you'll find other examples on our
download examples (/downloads/) :
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://www.jclark.com/xt/java/java.util.Date">
<xsl:template match="/">
<html>
<xsl:if test="function-available('date:to-string') and
function-available('date:new')">
<p><xsl:value-of select="date:to-string(date:new())"/></p>
</xsl:if>
</html>
</xsl:template>
</xsl:stylesheet>
The trick here is to declare a namespace for each class you'll want to
use (here java.util.Date), to make sure this class is available from
your classpath and to take care to the name mappings :
> A call to a function ns:foo where ns is bound to a namespace of the form > http://www.jclark.com/xt/java/className is treated as a call of the static
> method foo of the class with fully-qualified name className. Hyphens in method *
> names are removed with the character following the hyphen being upper-cased.
> Overloading based on number of parameters is supported; overloading based
> on parameter types is not. A non-static method is treated like a static method
> with the this object as an additional first argument. A constructor is treated
> like a static method named new. Extension functions can return objects of
> arbitrary types which can then be passed as arguments to other extension
> functions or stored in variables.
You need also to know that XT is very strict on the types you'll be
using.
For instance, if you define a variable as :
<xsl:variable name="foo">bar</xsl:variable>
$foo is a result tree fragment, not a string and a call to a method
needing a string as parameter will fail.
To avoid these kind of problems, you must either be very careful or
explicitly convert your variables (use string($foo) or
normalize-space($foo) in our example.
> I'm trying to convert the following Java code into XSLT extension calls, but
> I keep getting error messages like "overloaded constructor."
>
> String dateValue = someDate.toString( );
> String datePattern = "yyyyMMdd";
> SimpleDateFormat formatter = new SimpleDateFormat( datePattern );
> java.util.Date utilDate = formatter.parse( dateValue );
> String newDateValue = utilDate.toString( );
Can you give us your full example ?
I don't see how you include the above Java code in your XSLT sheet...
> Thanks again for any help,
You're welcome,
Eric
> Peter
>
> --
> Mailing list for the XT users community. (http://oldflbank.com)
> (mailto:list4xt-request@4xt.org?Subject=unsubscribe to unsubscribe)
--
------------------------------------------------------------------------
Eric van der Vlist Dyomedea http://worldwide-extension.org
http://entrustbankcard.com - http://thetechielifestyle.com http://buildingforamerica.org
------------------------------------------------------------------------
--
Mailing list for the XT users community. (http://ashokacreditunion.org)
(mailto:list4xt-request@4xt.org?Subject=unsubscribe to unsubscribe)
Archive générée par hypermail 2b28 le 06/11/2001 - 11:46 CET
webmaster@4xt.org
|