RE: [xsl] xslt extensions error : 'Call to extension function fai led'

Subject: RE: [xsl] xslt extensions error : 'Call to extension function fai led'
From: Amit Deshpande <adeshpande@xxxxxxxxxxxxxxxx>
Date: Wed, 2 Oct 2002 07:26:15 -0700
Here is the code that I am using. This is the basic example that you get
from xalan, the example with slight modifications.
The code is as below,
package com.example.util;

import java.util.Hashtable;

public class MyCounter {
  static Hashtable counters = new Hashtable ();

  public void init(org.apache.xalan.xslt.XSLProcessorContext context,
                   org.w3c.dom.Element elem)
    String name = elem.getAttribute("name");
    String value = elem.getAttribute("value");
    int val;
      val = Integer.parseInt (value);
    catch (NumberFormatException e)
      e.printStackTrace ();
      val = 0;
    counters.put (name, new Integer (val));

  public int read(String name)
    Integer cval = (Integer)counters.get(name);
    return (cval == null) ? 0 : cval.intValue();

  public void incr(org.apache.xalan.xslt.XSLProcessorContext context,
                   org.w3c.dom.Element elem) {
    String name = elem.getAttribute("name");
    Integer cval = (Integer) counters.get(name);
    int nval = (cval == null) ? 0 : (cval.intValue () + 1);
    counters.put (name, new Integer (nval));

The xml and xsl source files are 

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="";

  <lxslt:component prefix="counter"
                   elements="init incr" functions="read">
    <lxslt:script lang="javaclass" src="com.example.util.MyCounter"/>

  <xsl:template match="/">
      <H1>Java Example</H1>
      <counter:init name="index" value="1"/>
      <p>Here are the names in alphabetical order by last name:</p>
      <xsl:for-each select="doc/name">
        <xsl:sort select="@last"/>
        <xsl:sort select="@first"/>
        <xsl:value-of select="counter:read('index')"/>
        <xsl:text>]. </xsl:text>
        <xsl:value-of select="@last"/>
        <xsl:text>, </xsl:text>
        <xsl:value-of select="@first"/>
        <counter:incr name="index"/>

<?xml version="1.0"?>
  <name first="Sanjiva" last="Weerawarana"/>
  <name first="Joseph" last="Kesselman"/>
  <name first="Stephen" last="Auriemma"/>
  <name first="Igor" last="Belakovskiy"/>    
  <name first="David" last="Marston"/>
  <name first="David" last="Bertoni"/>
  <name first="Donald" last="Leslie"/>
  <name first="Emily" last="Farmer"/>
  <name first="Myriam" last="Midy"/>
  <name first="Paul" last="Dick"/>
  <name first="Scott" last="Boag"/>
  <name first="Shane" last="Curcuru"/>
  <name first="Marcia" last="Hoffman"/>
  <name first="Noah" last="Mendelsohn"/>
  <name first="Alex" last="Morrow"/>    

Finally the code for transforming the xml and xsl to HTML is as follows:
(This is a JSP page)

    XSLTProcessor processor = XSLTProcessorFactory.getProcessor(
                                        new XML4JLiaison4dom() );
    XSLTInputSource xmlSource = new XSLTInputSource("D://numlist.xml" );
    XSLTInputSource xslSource = new XSLTInputSource("D://4-numlistJava.xsl"
    XSLTResultTarget result = new XSLTResultTarget( out );
    processor.process( xmlSource, xslSource, result );

The output that I get is 

Java Example
Here are the names in alphabetical order by last name:
[]. Auriemma, Stephen
[]. Belakovskiy, Igor
[]. Bertoni, David
[]. Boag, Scott
[]. Curcuru, Shane
[]. Dick, Paul
[]. Farmer, Emily
[]. Hoffman, Marcia
[]. Kesselman, Joseph
[]. Leslie, Donald
[]. Marston, David
[]. Mendelsohn, Noah
[]. Midy, Myriam
[]. Morrow, Alex
[]. Weerawarana, Sanjiva

So basically the extension function is not being called. The error message
that I got is 

"Call to extension function failed: com.example.util.MyCounter"

This is all the error that I am getting and I have no clue where the error
Any help on this will be appreciated.


-----Original Message-----
From: Vasu Chakkera [mailto:vasucv@xxxxxxxxxxx]
Sent: Wednesday, October 02, 2002 8:41 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] xslt extensions error : 'Call to extension function

It is difficult to tell you what the problem is , unless u show the code.But

it is very likely that you have not given the namespace declaration 
for example, if u have a class that is called com.myexample.myclass
and if u wanted to refer to it as myclass, then your <stylesheet> element 
should look like.

<xsl:stylesheet version="1.0" 
xmlns:myclass = "com.myexample.myclass"  extension-element-prefixes 

and u must refer to the class method with "myclass". eg..
if u have a method called calculate() in your class, then
<xsl:value-of select="myclass:calculate()"/>
would make a call to the calculate() method of the class myclass.

>	I am trying to use xslt java extensions and am having problems when
>I write
>my own custom classes and try to use them. When I use the "xmlns:java"
>namespace the code runs fine.
>The error I get when using my custom class is : "Call to extension function
>failed: com.example.DateFormatter". The problem is the error doesnt give 
>much information. Does anyone know what the possible cause'(s) of this 
>are. Btw the code happens to run on an appserver. Thanks in advance for all
>the help.

MSN Photos is the easiest way to share and print your photos:

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread