You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Matthias Brunner <mb...@blumenstrasse.vol.at> on 2001/03/11 23:56:52 UTC

Extension functions not working

Hello!

I use the extension feature of Xalan (v1.2.2) to query a database.
Defining extension elements works fine. But when I use extension
functions I get the following error message:

Call to extension function failed: method call/new failed:
java.lang.reflect.InvocationTargetException target exception:
java.lang.RuntimeException: ElemTemplateElement error: Can not resolve
namespace prefix: jdbc


Yet this namespace is defined in the stylesheet:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"
    xmlns:lxslt="http://xml.apache.org/xslt"
    xmlns:jdbc="http://xxxxx/xalan/extensions/jdbc"
    extension-element-prefixes="jdbc">

<lxslt:component prefix="jdbc"
        elements="update" functions="getid">
<lxslt:script lang="javaclass" src="com.gmg.xalan.extensions.JDBC"/>
</lxslt:component>

  <xsl:template match="entry">
  	<jdbc:update
	  val1="jdbc:getid('SELECT id FROM lp WHERE dt=?','',$dt)"
	  val2="@type"
	  query="INSERT INTO entry_type VALUES(NULL,?,?)"/>

	  <xsl:apply-templates/>
  </xsl:template>
...

The functions/elements resolve to this java class:

public class JDBC {
public String getid(String selectQuery, String insertQuery, String
names,
                        String values)
{...}

public void update(XSLProcessorContext context, Element element)
                 throws SQLException, SAXException
{...}

...

}

As I said before, update is getting called and acts nicely but getid
does not!
Could anyone please help me?

Best regards!
-- 
Matthias Brunner <mb...@blumenstrasse.vol.at>
PGP FP 7862 32B3 3B75 292A F76F  5042 8587 21AB 5B89 D501
Check out http://blumenstrasse.vol.at/~mb/gpgkey.asc

Re: Extension functions not working

Posted by Gary L Peskin <ga...@firstech.com>.
Matthias Brunner wrote:
> Thanks for your advice. Although it caused me some grief I ported the
> application to Xalan2 (the compatibility API did not work for me) :-)
> Now it works.

Glad to hear things are working now!

> 
> One question remains:
> I used to compile the stylesheet and save it in a StylesheetRoot object.
> How do I prevent that a stylesheet is evaluated several times when I
> transform several documents?
> Does this happen automatically when I call
> factory.newTransformer(stylesheet)?

Do this instead:

Templates myTemplate = factory.newTemplates(stylesheet);

Then, each time you do your transform, do:

myTemplate.newTransformer()

to get your transformer.  This is a fast method which will create a new
Transformer from your saved Templates object.

Gary

Re: Extension functions not working

Posted by Matthias Brunner <mb...@blumenstrasse.vol.at>.
Gary L Peskin wrote:
> 
> Matthias Brunner wrote:
> >
> > Hello!
> >
> > I use the extension feature of Xalan (v1.2.2) to query a database.
> > Defining extension elements works fine. But when I use extension
> > functions I get the following error message:
> >
> > Call to extension function failed: method call/new failed:
> > java.lang.reflect.InvocationTargetException target exception:
> > java.lang.RuntimeException: ElemTemplateElement error: Can not resolve
> > namespace prefix: jdbc
> 
> I'm not sure what's going on in XalanJ1.2.2 but I did get this working
> with no problems in XalanJ2.  Perhaps you could try to migrate to the
> current version of XalanJ2 and report any problems that you're still
> having then.
> 
> Sorry but the XalanJ1.2.2 code is just too "out of focus" for me to
> troubleshoot it there.
> 

Thanks for your advice. Although it caused me some grief I ported the
application to Xalan2 (the compatibility API did not work for me) :-)
Now it works. 

One question remains:
I used to compile the stylesheet and save it in a StylesheetRoot object.
How do I prevent that a stylesheet is evaluated several times when I
transform several documents?
Does this happen automatically when I call
factory.newTransformer(stylesheet)?

Best regards!
-- 
Matthias Brunner <mb...@blumenstrasse.vol.at>
PGP FP 7862 32B3 3B75 292A F76F  5042 8587 21AB 5B89 D501
Check out http://blumenstrasse.vol.at/~mb/gpgkey.asc

Re: Extension functions not working

Posted by Gary L Peskin <ga...@firstech.com>.
Matthias Brunner wrote:
> 
> Hello!
> 
> I use the extension feature of Xalan (v1.2.2) to query a database.
> Defining extension elements works fine. But when I use extension
> functions I get the following error message:
> 
> Call to extension function failed: method call/new failed:
> java.lang.reflect.InvocationTargetException target exception:
> java.lang.RuntimeException: ElemTemplateElement error: Can not resolve
> namespace prefix: jdbc

Matthias --

I'm not sure what's going on in XalanJ1.2.2 but I did get this working
with no problems in XalanJ2.  Perhaps you could try to migrate to the
current version of XalanJ2 and report any problems that you're still
having then.

Sorry but the XalanJ1.2.2 code is just too "out of focus" for me to
troubleshoot it there.

Gary