Problem calling external java method 2005-10-20 - By Chris Bare
Thanks a ton. That way works!
It seems that the crucial difference is putting the fully-qualified-classname (mypackage.MyClass) in the namespace rather than in the select attributes. For example this works just fine:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java_util_date="http://xml.apache.org/xalan/java/java.util.Date" version="1.0">
<xsl:output method="xml"/> <xsl:variable name="now" select="java_util_date:new()"/>
<xsl:template match="/"> <foobar> <xsl:attribute name="square"> <xsl:value-of select="java_util_date:toString($now)"/> </xsl:attribute> </foobar> </xsl:template>
</xsl:stylesheet>
...while this fails trying to find a static method:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dammit="http://xml.apache.org/xalan/java" version="1.0">
<xsl:output method="xml"/> <xsl:variable name="now" select="dammit:java.util.Date.new()"/>
<xsl:template match="/"> <foobar> <xsl:attribute name="square"> <xsl:value-of select="dammit:java.util.Date.toString($now)"/> </xsl:attribute> </foobar> </xsl:template>
</xsl:stylesheet>
java.lang.NoSuchMethodException: For extension function, could not find method static java.util.Date.toString([ExpressionContext,] #UNKNOWN (java.util.Date)).
I wonder if this is the intended behavior. I was originially thinking the only difference between calling a static method and an instance method was whether you pass in the instance as a parameter.
I haven't tried all the permutations, but the http://xml.apache.org/xalan/java/ namespace seems to be optional.
Anyway, huge thanks to John!!
-----Original Message----- From: John Gentilin [mailto:gentijo@(protected)] Sent: Wednesday, October 19, 2005 6:18 PM To: Chris Bare Cc: xalan-j-users@(protected) Subject: Re: Problem calling external java method
Chris,
I declare my extensions, in interpretive mode, a bit differently. I think the java namespace may have special meaning. The example below declares a class called CategoryPageMgr that exists in the custom package.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:catmgr="custom.CategoryPageMgr" exclude-result-prefixes="catmgr" extension-element-prefixes="catmgr">
<xsl:param name="CategoryMgr" select="catmgr:new()"/>
<xsl:template match="foo"> <data> <xsl:value-of select="catmgr:getCategoryPage($CategoryMgr, $category, $localID, $pageData)" /> </data> </xsl:template>
</xsl:stylesheet>
Hope that helps John G
Chris Bare wrote:
>Help! > >...
|
|