Re: any known issues with Xalan 2.7.1 distributed with Sun's JRE 6?
Nathan Nadeau <[email protected]> Mon, 10 May 2010 10:55:55 -0400
| Newsgroups | gmane.text.xml.xalan.java.user |
|---|---|
| Organization | Gleim Publications |
| Message-ID | <[email protected]> |
Adrian Herscu wrote:
> Hi all,
>
> I am trying to implement few XSL extension functions in Java and call
> them from my XSL template.
>
> I discovered that the ExpressionContext interface is not available and
> so all the org.apache namespace (there is something like
> com.sum.org.apache...internal.ExpressionContext but the compiler
> refuses it).
>
> Also discovered that no matter what the referenced FQCN is, the XSL
> process always tries to invoke methods in the java.lang.String class.
>
> For example
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xalan="http://xml.apache.org/xalan"
> xmlns:utils="com.acme.followed.by.this.garbage:@%#$%@#^#%#$"
> extension-element-prefixes="utils">
Maybe you need to add a <xalan:component> section to your XSLT after the
namespace declarations:
<xalan:component prefix="utils">
<xalan:script lang="javaclass" src="yourClassName"/>
</xalan:component>
Or if your extension is implemented in Java it is recommended to use the
abbreviated syntax for extensions implemented in Java, which does not
require the <xalan:component> element. Setting the xmlns attribute alone
(which your example shows) is not enough since that value is not used to
actually locate your class, as far as I can tell.
See http://xml.apache.org/xalan-j/extensions.html and
http://xml.apache.org/xalan-j/extensions.html#java-namespace for more
details.
Also of course make sure your class is in the classpath.
>
>
> Then this one works by calling the java.lang.String.length method !
>
> <xsl:value-of select="utils:length('fff')" />
>
> Regards,
> Adrian.
>
--
Nathan Nadeau
[email protected]
Software Development
Gleim Publications, Inc.
http://www.gleim.com