This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Extension Functions


I use Xerces but the implementation may be similar.

*****NOTE: I'm not sure if it is a bug or not but there is an issue with
the jre.  The jre (jdk1.2 and jdk1.2.2) will not allow a class that is
loaded in the ext directory to find/communicate with a class in the
classpath, and vice versa.  I know is sound funny, so go ahead and test
it yourself. Most people use the classpath exclusively, but for some
reason we and put the xalan jar files in the ext directory and because
of this issue it took us a while to figure out why the jre could find
our extension function class in the classpath.

stylesheet implementation...

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:java="http://xml.apache.org/xslt/java"
				version = "1.0">

<xsl:template...

	<xsl:if
test="java:net.xml.exporter.XSLExtFunctions.verifyMoreInfo(string(./@id),
string(substring-before(//@id,'-')))"> 
		<p/>
		<a>
		<xsl:attribute name="href">javascript:launchMoreInfo("<xsl:value-of
select="@id"/>");</xsl:attribute>
		Click here for More Info</a>
	</xsl:if>

</xsl:template>


This calls a function 'verifyMoreInfo()' in the class XSLExtFunctions. 
In this case it returns a boolean value, but I was reading the other day
on xalan-j mailing list where a developer passes a java object as a
param to the stylesheet and then passes the java object to a java
extension function (he did not use the java object in the XSL directly).

> 1. How can I call my own java functions in xsl?
For Xalan...make sure the xalan.jar, bsf.jar, bsfengine.jar, and the
parser files are in your classpath, not the ext directory.  Code you
java class and make sure it is in the classpath also.  Then use the
above stylesheet implementation to call it from within your xsl.

It took me a while to figure this out because of the NOTE above, once
that was resolved the documentation for Xalan extension functions seemed
clear.

Good luck,

-- 
*******************************************
Allen Haws
Unicon Inc.

Email:  joeshmoe@unicon.net
Phone:  480.926.2368 ext 343
Direct: 480.558.2445
*******************************************


Shirin Ahmadzadeh-Shad wrote:
> 
>  Hi,
> 
> I have two questions about extension functions:
> 
> 1. How can I call my own java functions in xsl?
> I couldn't find any example other than Date for XT.I'm using XT for win32
> and don't know where I have to put my *.class files.
> It get the following message
> 
> 'implementation of extention namespace not available'
> 
> 2. How can I do these? What should I give as fully-qualified name of the
> java class?
> int i,j;
> j=j*i  or j=j/i
> 
>  Thank you
>  Shirin
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]