You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Wade, John F. (MSFC-NAS902099)[TBE]" <Jo...@nasa.gov> on 2007/04/27 20:52:20 UTC
Xalan extension functions
As long as we're on the topic of XALAN extension functions, I too am looking for some help. I've got an existing XALAN-J based system (I didn't create it) that I'm trying to add on to. I want to create a simple extension function in JAVA. The XALAN-J documentation says stuff written in JAVA doesn't require BSF.
So - I went to work on one of the XSLs: added a simple namespace and defined a component as in the example at http://xml.apache.org/xalan-j/extensions.html#ex-java I wrote and compiled an extension function; currently just of the "Hello, world" sort. So far, so good.
Problem arises when I try and use the extension function in something like <xsl:value-of select="mytest:hello()"/> XALAN throws a "can't find the class" exception no matter where I put the .class file.
Those folks out there with some experience implementing JAVA extensions - I'd be grateful for some help figuring this out. I'm sure it's something very simple, but I don't know where to look next.
*********************************
John F. Wade, PE
MSFC iPV Integration Lead
Re: Xalan extension functions
Posted by Rick Gordon <rg...@ingeniux.com>.
yes, that's what i'm saying - switching to 2.7 Xalan (and the updated
BSF and Rhino) caused the problem.
it'll take me a little bit to setup the test again to generate a stack
trace. I think it was when
trying to use TransformerFactory.newInstance() but I don't recall the
rest right now.
Kevin Cormier wrote:
> Hi Rick,
>
> Just to clarify, are you saying that the exact same stylesheets and
> extension functions that worked with Xalan 2.6.0 do not work with 2.7.0?
>
> Can you provide the stack trace of the exception that you're seeing?
>
> Kevin Cormier
> Software Developer, XSLT Development
> IBM Toronto Lab, D1-435
> E-mail: kcormier@ca.ibm.com
>
>
>
> Rick Gordon
> <rgordon@ingeniux
> .com> To
>
> 04/27/2007 04:09 cc
> PM xalan-j-users@xml.apache.org
> Subject
> Re: Xalan extension functions
>
>
>
>
>
>
>
>
>
>
> It certainly seems like a classpath problem in my case as well, but BSF
> is available, and seems to be installed
> correctly. Yet I haven't been able to figure out where its trying to
> load it from and why. Paths are further
> complicated by running under Tomcat I know.
>
> Normally we put Xalan-J.jar, bsf.jar, js.jar into
> tomcat5/common/endorsed/ and it pulls them from the correct place.
> Doing so with Xalan 2.7 it does not seem to find them there. I've also
> made sure that valid versions were installed
> in the /usr/share/java (their default location) and in
> /etc/alternatives/jre/lib/endorsed, to no avail.
>
> I cannot provide a full example obviously, but here's a rough breakdown
> of how we invoke things, if that helps.
> In our case we need to work both in an MSXSL environment as well as a
> Xalan-J environment, which makes it a little
> more complicated - at least at the xslt level.
>
> A stylesheet that wants to use the extension functions does this (I've
> pulled things from a couple of places here, hopefully its coherent.)
>
> <!DOCTYPE xsl:stylesheet [<!ENTITY js_include SYSTEM
> "calendar_functions.js">]>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:msxsl="urn:schemas-microsoft-com:xslt"
> xmlns:xalan="http://xml.apache.org/xalan"
> xmlns:calendar="urn:calendarlib"
> xmlns:igxlib="urn:igxlibns"
> extension-element-prefixes="calendar igxlib msxsl xalan"
> exclude-result-prefixes="calendar igxlib msxsl xalan"
> version="1.0">
>
> <xsl:include href="include-scripts.xsl"/>
>
> and then has its use of the extension functions, using syntax like this:
>
> <xsl:value-of select="calendar:getTodaysYear()" />
>
>
> The xsl pulling in the scripts, "include-scripts.xsl" then looks
> something like this:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE xsl:stylesheet [<!ENTITY js_include SYSTEM
> "extension_functions.js">]>
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:msxsl="urn:schemas-microsoft-com:xslt"
> xmlns:xalan="http://xml.apache.org/xalan"
> xmlns:calendar="urn:calendarlib"
> xmlns:igxlib="urn:igxlibns"
> extension-element-prefixes="igxlib"
> version="1.0">
>
> <msxsl:script language="JavaScript" implements-prefix="igxlib">
> &js_include;
> </msxsl:script>
>
> <xalan:component prefix="igxlib" elements=""
> functions="IsNewMonth GenerateMonth GenerateDay GenerateYear
> formatBaseURL RandomIndex RandomSequence
> IndexedItemFromList toLower UTCtoLocalTime
> fitSizeWidth replaceStr matchCatMultiMulti" >
>
> <xalan:script lang="javascript">
> &js_include;
> </xalan:script>
> </xalan:component>
> </xsl:stylesheet>
>
>
> Wade, John F. (MSFC-NAS902099)[TBE] wrote:
>
>> Classpath has been my thought, too. I'm a real beginner at this, and
>> the environment I'm working with has two variants, so I'm not sure how
>> to determine what the classpath is in each case.
>> But, we'll start with the stylesheet and JAVA code on Monday and go
>> from there.
>>
>> Thanks.
>>
>> JFW
>>
>>
>>
>> ------------------------------------------------------------------------
>> *From:* Kevin Cormier [mailto:kcormier@ca.ibm.com]
>> *Sent:* Fri 4/27/2007 3:11 PM
>> *To:* Wade, John F. (MSFC-NAS902099)[TBE]
>> *Cc:* xalan-j-users@xml.apache.org
>> *Subject:* Re: Xalan extension functions
>>
>> Hi John,
>>
>> All I can think of with the information you've given is to check that
>>
> your
>
>> class is on the classpath.
>>
>> Could you send your stylesheet and Java class, and also show how you
>> invoked the transformation and what the full error message was?
>>
>>
>>
>
>
>
>
Re: Xalan extension functions
Posted by Kevin Cormier <kc...@ca.ibm.com>.
Hi Rick,
Just to clarify, are you saying that the exact same stylesheets and
extension functions that worked with Xalan 2.6.0 do not work with 2.7.0?
Can you provide the stack trace of the exception that you're seeing?
Kevin Cormier
Software Developer, XSLT Development
IBM Toronto Lab, D1-435
E-mail: kcormier@ca.ibm.com
Rick Gordon
<rgordon@ingeniux
.com> To
04/27/2007 04:09 cc
PM xalan-j-users@xml.apache.org
Subject
Re: Xalan extension functions
It certainly seems like a classpath problem in my case as well, but BSF
is available, and seems to be installed
correctly. Yet I haven't been able to figure out where its trying to
load it from and why. Paths are further
complicated by running under Tomcat I know.
Normally we put Xalan-J.jar, bsf.jar, js.jar into
tomcat5/common/endorsed/ and it pulls them from the correct place.
Doing so with Xalan 2.7 it does not seem to find them there. I've also
made sure that valid versions were installed
in the /usr/share/java (their default location) and in
/etc/alternatives/jre/lib/endorsed, to no avail.
I cannot provide a full example obviously, but here's a rough breakdown
of how we invoke things, if that helps.
In our case we need to work both in an MSXSL environment as well as a
Xalan-J environment, which makes it a little
more complicated - at least at the xslt level.
A stylesheet that wants to use the extension functions does this (I've
pulled things from a couple of places here, hopefully its coherent.)
<!DOCTYPE xsl:stylesheet [<!ENTITY js_include SYSTEM
"calendar_functions.js">]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:calendar="urn:calendarlib"
xmlns:igxlib="urn:igxlibns"
extension-element-prefixes="calendar igxlib msxsl xalan"
exclude-result-prefixes="calendar igxlib msxsl xalan"
version="1.0">
<xsl:include href="include-scripts.xsl"/>
and then has its use of the extension functions, using syntax like this:
<xsl:value-of select="calendar:getTodaysYear()" />
The xsl pulling in the scripts, "include-scripts.xsl" then looks
something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xsl:stylesheet [<!ENTITY js_include SYSTEM
"extension_functions.js">]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:calendar="urn:calendarlib"
xmlns:igxlib="urn:igxlibns"
extension-element-prefixes="igxlib"
version="1.0">
<msxsl:script language="JavaScript" implements-prefix="igxlib">
&js_include;
</msxsl:script>
<xalan:component prefix="igxlib" elements=""
functions="IsNewMonth GenerateMonth GenerateDay GenerateYear
formatBaseURL RandomIndex RandomSequence
IndexedItemFromList toLower UTCtoLocalTime
fitSizeWidth replaceStr matchCatMultiMulti" >
<xalan:script lang="javascript">
&js_include;
</xalan:script>
</xalan:component>
</xsl:stylesheet>
Wade, John F. (MSFC-NAS902099)[TBE] wrote:
> Classpath has been my thought, too. I'm a real beginner at this, and
> the environment I'm working with has two variants, so I'm not sure how
> to determine what the classpath is in each case.
> But, we'll start with the stylesheet and JAVA code on Monday and go
> from there.
>
> Thanks.
>
> JFW
>
>
>
> ------------------------------------------------------------------------
> *From:* Kevin Cormier [mailto:kcormier@ca.ibm.com]
> *Sent:* Fri 4/27/2007 3:11 PM
> *To:* Wade, John F. (MSFC-NAS902099)[TBE]
> *Cc:* xalan-j-users@xml.apache.org
> *Subject:* Re: Xalan extension functions
>
> Hi John,
>
> All I can think of with the information you've given is to check that
your
> class is on the classpath.
>
> Could you send your stylesheet and Java class, and also show how you
> invoked the transformation and what the full error message was?
>
>
Re: Xalan extension functions
Posted by Rick Gordon <rg...@ingeniux.com>.
It certainly seems like a classpath problem in my case as well, but BSF
is available, and seems to be installed
correctly. Yet I haven't been able to figure out where its trying to
load it from and why. Paths are further
complicated by running under Tomcat I know.
Normally we put Xalan-J.jar, bsf.jar, js.jar into
tomcat5/common/endorsed/ and it pulls them from the correct place.
Doing so with Xalan 2.7 it does not seem to find them there. I've also
made sure that valid versions were installed
in the /usr/share/java (their default location) and in
/etc/alternatives/jre/lib/endorsed, to no avail.
I cannot provide a full example obviously, but here's a rough breakdown
of how we invoke things, if that helps.
In our case we need to work both in an MSXSL environment as well as a
Xalan-J environment, which makes it a little
more complicated - at least at the xslt level.
A stylesheet that wants to use the extension functions does this (I've
pulled things from a couple of places here, hopefully its coherent.)
<!DOCTYPE xsl:stylesheet [<!ENTITY js_include SYSTEM
"calendar_functions.js">]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:calendar="urn:calendarlib"
xmlns:igxlib="urn:igxlibns"
extension-element-prefixes="calendar igxlib msxsl xalan"
exclude-result-prefixes="calendar igxlib msxsl xalan"
version="1.0">
<xsl:include href="include-scripts.xsl"/>
and then has its use of the extension functions, using syntax like this:
<xsl:value-of select="calendar:getTodaysYear()" />
The xsl pulling in the scripts, "include-scripts.xsl" then looks
something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xsl:stylesheet [<!ENTITY js_include SYSTEM
"extension_functions.js">]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:calendar="urn:calendarlib"
xmlns:igxlib="urn:igxlibns"
extension-element-prefixes="igxlib"
version="1.0">
<msxsl:script language="JavaScript" implements-prefix="igxlib">
&js_include;
</msxsl:script>
<xalan:component prefix="igxlib" elements=""
functions="IsNewMonth GenerateMonth GenerateDay GenerateYear
formatBaseURL RandomIndex RandomSequence
IndexedItemFromList toLower UTCtoLocalTime
fitSizeWidth replaceStr matchCatMultiMulti" >
<xalan:script lang="javascript">
&js_include;
</xalan:script>
</xalan:component>
</xsl:stylesheet>
Wade, John F. (MSFC-NAS902099)[TBE] wrote:
> Classpath has been my thought, too. I'm a real beginner at this, and
> the environment I'm working with has two variants, so I'm not sure how
> to determine what the classpath is in each case.
> But, we'll start with the stylesheet and JAVA code on Monday and go
> from there.
>
> Thanks.
>
> JFW
>
>
>
> ------------------------------------------------------------------------
> *From:* Kevin Cormier [mailto:kcormier@ca.ibm.com]
> *Sent:* Fri 4/27/2007 3:11 PM
> *To:* Wade, John F. (MSFC-NAS902099)[TBE]
> *Cc:* xalan-j-users@xml.apache.org
> *Subject:* Re: Xalan extension functions
>
> Hi John,
>
> All I can think of with the information you've given is to check that your
> class is on the classpath.
>
> Could you send your stylesheet and Java class, and also show how you
> invoked the transformation and what the full error message was?
>
>
RE: Xalan extension functions
Posted by "Wade, John F. (MSFC-NAS902099)[TBE]" <Jo...@nasa.gov>.
Fixed.
Still seeing the error-
...Instance method call to method new requires an Object instance as
first argument
Thoughts?
-----Original Message-----
From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
Sent: Friday, May 11, 2007 3:51 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
Oops, I meant to say that the namespace should be
xmlns:MT="xalan://ManipulateText", not
xmlns:MT="xalan://ManipulateText.ManipulateText"
RE: Xalan extension functions
Posted by Kevin Cormier <kc...@ca.ibm.com>.
Oops, I meant to say that the namespace should be
xmlns:MT="xalan://ManipulateText", not
xmlns:MT="xalan://ManipulateText.ManipulateText"
Kevin Cormier
Software Developer, XSLT Development
IBM Toronto Lab, D1-435
E-mail: kcormier@ca.ibm.com
"Wade, John F.
(MSFC-NAS902099)[
TBE]" To
<John.F.Wade@nasa Kevin Cormier/Toronto/IBM@IBMCA
.gov> cc
<xa...@xml.apache.org>
05/11/2007 04:45 Subject
PM RE: Xalan extension functions
OK. I see the explanation material you're referring to. It's making
better sense now.
I modified the java to-
import java.util.*;
public class ManipulateText
{
public String Unescape(String mydata)
{
return mydata;
}
}
The XSL starts with-
Changed the top material to-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
xmlns:MT="xalan://ManipulateText.ManipulateText"
extension-element-prefixes="MT"
exclude-result-prefixes="doc"
version="1.0">
And contains-
<xsl:variable name="mt" select="MT:new()"/>
<xsl:variable name="result" select="MT:Unescape($mt, 'test')"/>
We're getting a different error now.
file:///C:/Program%20Files/Corel/XMetaL%204/Author/conversion/xsl/IPV-PR
OCEDURE/ipv-procedure/cleartext.xsl; Line #204; Column #44; XSLT Error
(javax.xml.transform.TransformerException):
javax.xml.transform.TransformerException: Instance method call to method
new requires an Object instance as first argument
I'm puzzled why the 'new' isn't behaving as expected.
Just to be clear - the java code ends up in a file called
ManipulateText.class that I've located in the same folder as the XSL.
I note with interest that if I delete the .class file, the error doesn't
change. Which suggests to me that the transformer isn't finding it in
the first place.
Fun and games on a Friday afternoon...
************************************
John F. Wade, PE
TBE
MSFC iPV Integration
CLV First Stage Flight Operations
256-961-2410
-----Original Message-----
From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
Sent: Friday, May 11, 2007 3:16 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
Hi John,
Please refer to
http://xml.apache.org/xalan-j/extensions.html#ext-functions
and scroll down a bit to the section titled "Class format namespace"
Since you want to specify the class as the namespace, you should use "
xmlns:MT="xalan://ManipulateText.ManipulateText" unless your class
actually is in package ManipulateText. Then what you have shown is
correct.
Your Unescape method is not static, so it needs an instance to operate
on.
Here is an example in Java and XSLT:
|------------------------------------+----------------------------------
--|
|Java |XSLT
|
|------------------------------------+----------------------------------
--|
|ManipulateText mt = new |<xsl:variable name="mt"
|
|ManipulateText(); |select="MT:new()"/>
|
|------------------------------------+----------------------------------
--|
|char result = mt.Unescape('p'); |<xsl:variable name="result"
|
| |select="MT:Unescape($mt, 'p')"/>
|
|------------------------------------+----------------------------------
--|
Notice how the instance becomes an extra first argument to the method.
Alternatively, you could just use a static method.
One last thing - in your stylesheet, you're passing in 'text' which is
not a char. I'm not sure exactly what happens in that case, but I
imagine you meant to use a String in your method.
Kevin Cormier
Software Developer, XSLT Development
IBM Toronto Lab, D1-435
E-mail: kcormier@ca.ibm.com
RE: Xalan extension functions
Posted by "Wade, John F. (MSFC-NAS902099)[TBE]" <Jo...@nasa.gov>.
OK. I see the explanation material you're referring to. It's making
better sense now.
I modified the java to-
import java.util.*;
public class ManipulateText
{
public String Unescape(String mydata)
{
return mydata;
}
}
The XSL starts with-
Changed the top material to-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
xmlns:MT="xalan://ManipulateText.ManipulateText"
extension-element-prefixes="MT"
exclude-result-prefixes="doc"
version="1.0">
And contains-
<xsl:variable name="mt" select="MT:new()"/>
<xsl:variable name="result" select="MT:Unescape($mt, 'test')"/>
We're getting a different error now.
file:///C:/Program%20Files/Corel/XMetaL%204/Author/conversion/xsl/IPV-PR
OCEDURE/ipv-procedure/cleartext.xsl; Line #204; Column #44; XSLT Error
(javax.xml.transform.TransformerException):
javax.xml.transform.TransformerException: Instance method call to method
new requires an Object instance as first argument
I'm puzzled why the 'new' isn't behaving as expected.
Just to be clear - the java code ends up in a file called
ManipulateText.class that I've located in the same folder as the XSL.
I note with interest that if I delete the .class file, the error doesn't
change. Which suggests to me that the transformer isn't finding it in
the first place.
Fun and games on a Friday afternoon...
************************************
John F. Wade, PE
TBE
MSFC iPV Integration
CLV First Stage Flight Operations
256-961-2410
-----Original Message-----
From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
Sent: Friday, May 11, 2007 3:16 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
Hi John,
Please refer to
http://xml.apache.org/xalan-j/extensions.html#ext-functions
and scroll down a bit to the section titled "Class format namespace"
Since you want to specify the class as the namespace, you should use "
xmlns:MT="xalan://ManipulateText.ManipulateText" unless your class
actually is in package ManipulateText. Then what you have shown is
correct.
Your Unescape method is not static, so it needs an instance to operate
on.
Here is an example in Java and XSLT:
|------------------------------------+----------------------------------
--|
|Java |XSLT
|
|------------------------------------+----------------------------------
--|
|ManipulateText mt = new |<xsl:variable name="mt"
|
|ManipulateText(); |select="MT:new()"/>
|
|------------------------------------+----------------------------------
--|
|char result = mt.Unescape('p'); |<xsl:variable name="result"
|
| |select="MT:Unescape($mt, 'p')"/>
|
|------------------------------------+----------------------------------
--|
Notice how the instance becomes an extra first argument to the method.
Alternatively, you could just use a static method.
One last thing - in your stylesheet, you're passing in 'text' which is
not a char. I'm not sure exactly what happens in that case, but I
imagine you meant to use a String in your method.
Kevin Cormier
Software Developer, XSLT Development
IBM Toronto Lab, D1-435
E-mail: kcormier@ca.ibm.com
RE: Xalan extension functions
Posted by Kevin Cormier <kc...@ca.ibm.com>.
Hi John,
Please refer to http://xml.apache.org/xalan-j/extensions.html#ext-functions
and scroll down a bit to the section titled "Class format namespace"
Since you want to specify the class as the namespace, you should use "
xmlns:MT="xalan://ManipulateText.ManipulateText" unless your class actually
is in package ManipulateText. Then what you have shown is correct.
Your Unescape method is not static, so it needs an instance to operate on.
Here is an example in Java and XSLT:
|------------------------------------+------------------------------------|
|Java |XSLT |
|------------------------------------+------------------------------------|
|ManipulateText mt = new |<xsl:variable name="mt" |
|ManipulateText(); |select="MT:new()"/> |
|------------------------------------+------------------------------------|
|char result = mt.Unescape('p'); |<xsl:variable name="result" |
| |select="MT:Unescape($mt, 'p')"/> |
|------------------------------------+------------------------------------|
Notice how the instance becomes an extra first argument to the method.
Alternatively, you could just use a static method.
One last thing - in your stylesheet, you're passing in 'text' which is not
a char. I'm not sure exactly what happens in that case, but I imagine you
meant to use a String in your method.
Kevin Cormier
Software Developer, XSLT Development
IBM Toronto Lab, D1-435
E-mail: kcormier@ca.ibm.com
"Wade, John F.
(MSFC-NAS902099)[
TBE]" To
<John.F.Wade@nasa Kevin Cormier/Toronto/IBM@IBMCA,
.gov> <xa...@xml.apache.org>
cc
05/11/2007 03:54
PM Subject
RE: Xalan extension functions
Picking this conversation back up... I'm trying the abbreviated syntax
as several recommended. Still getting an error.
ManipulateText.java code is this-
import java.util.*;
public class ManipulateText
{
public char Unescape(char mydata)
{
return mydata;
}
}
Test stylesheet starts with this-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:MT="xalan://ManipulateText.ManipulateText"
extension-element-prefixes="MT"
exclude-result-prefixes="doc"
version="1.0">
And later contains this-
<xsl:value-of select="MT:Unescape('text')"/>
And I'm now getting this error-
(Location of error unknown)XSLT Error
(javax.xml.transform.TransformerException):
java.lang.NoSuchMethodException: For extension function, could not find
method java.lang.String.Unescape([ExpressionContext,] ).
I tried the the two different flavors of "new" that were suggested, but
didn't get anywhere.
Suggestions?
RE: Xalan extension functions
Posted by "Wade, John F. (MSFC-NAS902099)[TBE]" <Jo...@nasa.gov>.
Picking this conversation back up... I'm trying the abbreviated syntax
as several recommended. Still getting an error.
ManipulateText.java code is this-
import java.util.*;
public class ManipulateText
{
public char Unescape(char mydata)
{
return mydata;
}
}
Test stylesheet starts with this-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:MT="xalan://ManipulateText.ManipulateText"
extension-element-prefixes="MT"
exclude-result-prefixes="doc"
version="1.0">
And later contains this-
<xsl:value-of select="MT:Unescape('text')"/>
And I'm now getting this error-
(Location of error unknown)XSLT Error
(javax.xml.transform.TransformerException):
java.lang.NoSuchMethodException: For extension function, could not find
method java.lang.String.Unescape([ExpressionContext,] ).
I tried the the two different flavors of "new" that were suggested, but
didn't get anywhere.
Suggestions?
RE: Xalan extension functions
Posted by Kevin Cormier <kc...@ca.ibm.com>.
Hi John,
You're receiving this error message because MyTest() is the constructor of
the class, so as per http://xml.apache.org/xalan-j/extensions.htm, you
should follow the instructions for creating a new object:
To create an instance of an object:
prefix:FQCN.new (args)
where prefix is the extension namespace prefix for the Java namespace and
FQCN is the fully qualified class name of the class whose constructor is to
be called. A new instance is to be created with the args constructor
arguments (if any). All constructor methods are qualified for method
selection.
Example: <xsl:variable name="myHash"
select="java:java.util.Hashtable.new()">
Also, you should consider using the abbreviated syntax, since it doesn't
add any functionality for Java extensions and is not supported in XSLTC.
See the aforementioned web page for more information.
Kevin Cormier
Software Developer, XSLT Development
IBM Toronto Lab, D1-435
Phone: 905-413-5771
E-mail: kcormier@ca.ibm.com
"Wade, John F.
(MSFC-NAS902099)[
TBE]" To
<John.F.Wade@nasa "Wade, John F.
.gov> \(MSFC-NAS902099\)[TBE]"
<Jo...@nasa.gov>, Kevin
05/02/2007 09:49 Cormier/Toronto/IBM@IBMCA
AM cc
<xa...@xml.apache.org>
Subject
RE: Xalan extension functions
It's not Monday anymore. Oh well.
Here's the test case java code. It does exactly nothing.
Import java.util.*;
public class MyTest
{
public MyTest()
{}
}
The namespace and component definitions are:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl=http://www.w3.org/1999/XSL/Transform
xmlns=http://www.w3.org/1999/xhtml
xmlns:doc=http://nwalsh.com/xsl/documentation/1.0
exclude-result-prefixes="doc"
xmlns:xalan=http://xml.apache.org/xalan
xmlns:mytest="MyTest"
extension-element-prefixes="mytest"
version="1.0">
<xalan:component prefix="mytest" functions="MyTest">
<xalan:script lang="javaclass" src="xalan://MyTest/"/>
</xalan:component>
Down in one of the templates I've added a line that says:
<xsl:value-of select="mytest:MyTest()"/>
And the error I get is:
(Location of error unknown)XSLT Error
(javax.xml.transform.TransformerException):
javax.xml.transform.TransformerException: Instance method call to method
MyTest requires an Object instance as first argument
...which isn't the error I remember getting last time I tried this, but one
thing at a time.
Suggestions?
*********************************
John F. Wade, PE
MSFC EO20 - TBE
From: Wade, John F. (MSFC-NAS902099)[TBE] [mailto:John.F.Wade@nasa.gov]
Sent: Fri 4/27/2007 3:29 PM
To: Kevin Cormier
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
Classpath has been my thought, too. I'm a real beginner at this, and the
environment I'm working with has two variants, so I'm not sure how to
determine what the classpath is in each case.
But, we'll start with the stylesheet and JAVA code on Monday and go from
there.
Thanks.
JFW
From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
Sent: Fri 4/27/2007 3:11 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]
Cc: xalan-j-users@xml.apache.org
Subject: Re: Xalan extension functions
Hi John,
All I can think of with the information you've given is to check that your
class is on the classpath.
Could you send your stylesheet and Java class, and also show how you
invoked the transformation and what the full error message was?
Re: Xalan extension functions
Posted by Santiago Pericas-Geertsen <Sa...@Sun.COM>.
John,
Like in Java, you can't invoke a constructor directly. See [1] for
how to create Java objects using 'new'. I believe the syntax you're
using would work for static methods, though.
-- Santiago
[1] http://xml.apache.org/xalan-j/extensions.html#ext-func-calls
On May 2, 2007, at 9:49 AM, Wade, John F. (MSFC-NAS902099)[TBE] wrote:
> It's not Monday anymore. Oh well.
>
> Here's the test case java code. It does exactly nothing.
> Import java.util.*;
>
> public class MyTest
>
> {
>
> public MyTest()
>
> {}
>
>
> }
>
>
> The namespace and component definitions are:
> <?xml version="1.0" encoding="UTF-8" ?>
> <xsl:stylesheet
> xmlns:xsl=http://www.w3.org/1999/XSL/Transform
> xmlns=http://www.w3.org/1999/xhtml
> xmlns:doc=http://nwalsh.com/xsl/documentation/1.0
> exclude-result-prefixes="doc"
> xmlns:xalan=http://xml.apache.org/xalan
> xmlns:mytest="MyTest"
> extension-element-prefixes="mytest"
> version="1.0">
>
> <xalan:component prefix="mytest" functions="MyTest">
> <xalan:script lang="javaclass" src="xalan://MyTest/"/>
> </xalan:component>
>
>
>
> Down in one of the templates I've added a line that says:
> <xsl:value-of select="mytest:MyTest()"/>
>
>
> And the error I get is:
>
> (Location of error unknown)XSLT Error
> (javax.xml.transform.TransformerException):
> javax.xml.transform.TransformerException: Instance method call to
> method MyTest requires an Object instance as first argument
> ...which isn't the error I remember getting last time I tried this,
> but one thing at a time.
>
> Suggestions?
>
> *********************************
> John F. Wade, PE
> MSFC EO20 - TBE
>
>
>
>
> From: Wade, John F. (MSFC-NAS902099)[TBE]
> [mailto:John.F.Wade@nasa.gov]
> Sent: Fri 4/27/2007 3:29 PM
> To: Kevin Cormier
> Cc: xalan-j-users@xml.apache.org
> Subject: RE: Xalan extension functions
>
> Classpath has been my thought, too. I'm a real beginner at this,
> and the environment I'm working with has two variants, so I'm not
> sure how to determine what the classpath is in each case.
> But, we'll start with the stylesheet and JAVA code on Monday and go
> from there.
>
> Thanks.
>
> JFW
>
>
>
> From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
> Sent: Fri 4/27/2007 3:11 PM
> To: Wade, John F. (MSFC-NAS902099)[TBE]
> Cc: xalan-j-users@xml.apache.org
> Subject: Re: Xalan extension functions
>
> Hi John,
>
> All I can think of with the information you've given is to check
> that your
> class is on the classpath.
>
> Could you send your stylesheet and Java class, and also show how you
> invoked the transformation and what the full error message was?
>
>
RE: Xalan extension functions
Posted by "Fuller, Alex" <Al...@Lodestarcorp.com>.
Hi John,
I believe your problem that you haven't created an instance of the
class in which you're asking Xalan to execute a method. Since your
extension is written in Java, you should get rid of the
<xalan:component> syntax and use the abbreviated syntax
<http://xml.apache.org/xalan-j/extensions.html#java-namespace> .
However, the lack of a package name may hurt you; I've never tried that.
If all you want to do is invoke the constructor, use syntax like:
<xsl:variable name="MyTest" select="mytest:new()"/>
The error message is saying that Xalan thinks you're trying to call an
instance method on your object. To do that you have to include the
instance of the object in the method call. So, if your class had a
method "public void launch(String destination)"
<xsl:value-of select="mytest:launch($MyTest, 'Mars')"/>
Hope that helps,
Alex
________________________________
From: Wade, John F. (MSFC-NAS902099)[TBE]
[mailto:John.F.Wade@nasa.gov]
Sent: Wednesday, May 02, 2007 8:50 AM
To: Wade, John F. (MSFC-NAS902099)[TBE]; Kevin Cormier
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
It's not Monday anymore. Oh well.
Here's the test case java code. It does exactly nothing.
Import java.util.*;
public class MyTest
{
public MyTest()
{}
}
The namespace and component definitions are:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl=http://www.w3.org/1999/XSL/Transform
xmlns=http://www.w3.org/1999/xhtml
xmlns:doc=http://nwalsh.com/xsl/documentation/1.0
exclude-result-prefixes="doc"
xmlns:xalan=http://xml.apache.org/xalan
xmlns:mytest="MyTest"
extension-element-prefixes="mytest"
version="1.0">
<xalan:component prefix="mytest" functions="MyTest">
<xalan:script lang="javaclass" src="xalan://MyTest/"/>
</xalan:component>
Down in one of the templates I've added a line that says:
<xsl:value-of select="mytest:MyTest()"/>
And the error I get is:
(Location of error unknown)XSLT Error
(javax.xml.transform.TransformerException):
javax.xml.transform.TransformerException: Instance method call to method
MyTest requires an Object instance as first argument
...which isn't the error I remember getting last time I tried
this, but one thing at a time.
Suggestions?
*********************************
John F. Wade, PE
MSFC EO20 - TBE
________________________________
From: Wade, John F. (MSFC-NAS902099)[TBE]
[mailto:John.F.Wade@nasa.gov]
Sent: Fri 4/27/2007 3:29 PM
To: Kevin Cormier
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
Classpath has been my thought, too. I'm a real beginner at
this, and the environment I'm working with has two variants, so I'm not
sure how to determine what the classpath is in each case.
But, we'll start with the stylesheet and JAVA code on Monday and
go from there.
Thanks.
JFW
________________________________
From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
Sent: Fri 4/27/2007 3:11 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]
Cc: xalan-j-users@xml.apache.org
Subject: Re: Xalan extension functions
Hi John,
All I can think of with the information you've given is to check
that your
class is on the classpath.
Could you send your stylesheet and Java class, and also show how
you
invoked the transformation and what the full error message was?
RE: Xalan extension functions
Posted by "Wade, John F. (MSFC-NAS902099)[TBE]" <Jo...@nasa.gov>.
Thanks, all, for the great suggestions. Am juggling several balls at the moment but will try this stuff out in the next few days and let you know how it goes.
*********************************
John F. Wade, PE
EDS Proposal Manager
________________________________
From: Sushy Behal [mailto:sbehal@cisco.com]
Sent: Wed 5/2/2007 1:50 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]; 'Kevin Cormier'
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
This works . Try this it would work too in your code if everything else is fine
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl=http://www.w3.org/1999/XSL/Transform <http://www.w3.org/1999/XSL/Transform>
xmlns=http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>
xmlns:xalan=http://xml.apache.org/xalan <http://xml.apache.org/xalan>
xmlns:mytest="MyTest"
extension-element-prefixes="mytest"
version="1.0">
<xalan:component prefix="mytest" functions="nodeLinkRef ">
<xalan:script lang="javaclass" src="MyTest"/>
</xalan:component>
<!-- Somewhere in code -->
<xsl:value-of select="mytest:nodeLinkRef(.)"/>
//Modify JAVA CODE
import java.util.*;
//import all other relevant packages
public class MyTest
{
public Node nodeLinkRef(Node node)
{
try{
// do anything yu want here and beand this will handle exceptions
}
catch(Exception e)
{
e.printStackTrace();
}
return node;
}
}
Thanks
Sushy
________________________________
From: Wade, John F. (MSFC-NAS902099)[TBE] [mailto:John.F.Wade@nasa.gov]
Sent: Wednesday, May 02, 2007 6:50 AM
To: Wade, John F. (MSFC-NAS902099)[TBE]; Kevin Cormier
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
It's not Monday anymore. Oh well.
Here's the test case java code. It does exactly nothing.
Import java.util.*;
public class MyTest
{
public MyTest()
{}
}
The namespace and component definitions are:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl=http://www.w3.org/1999/XSL/Transform
xmlns=http://www.w3.org/1999/xhtml
xmlns:doc=http://nwalsh.com/xsl/documentation/1.0
exclude-result-prefixes="doc"
xmlns:xalan=http://xml.apache.org/xalan
xmlns:mytest="MyTest"
extension-element-prefixes="mytest"
version="1.0">
<xalan:component prefix="mytest" functions="MyTest">
<xalan:script lang="javaclass" src="xalan://MyTest/"/>
</xalan:component>
Down in one of the templates I've added a line that says:
<xsl:value-of select="mytest:MyTest()"/>
And the error I get is:
(Location of error unknown)XSLT Error (javax.xml.transform.TransformerException): javax.xml.transform.TransformerException: Instance method call to method MyTest requires an Object instance as first argument
...which isn't the error I remember getting last time I tried this, but one thing at a time.
Suggestions?
*********************************
John F. Wade, PE
MSFC EO20 - TBE
________________________________
From: Wade, John F. (MSFC-NAS902099)[TBE] [mailto:John.F.Wade@nasa.gov]
Sent: Fri 4/27/2007 3:29 PM
To: Kevin Cormier
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
Classpath has been my thought, too. I'm a real beginner at this, and the environment I'm working with has two variants, so I'm not sure how to determine what the classpath is in each case.
But, we'll start with the stylesheet and JAVA code on Monday and go from there.
Thanks.
JFW
________________________________
From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
Sent: Fri 4/27/2007 3:11 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]
Cc: xalan-j-users@xml.apache.org
Subject: Re: Xalan extension functions
Hi John,
All I can think of with the information you've given is to check that your
class is on the classpath.
Could you send your stylesheet and Java class, and also show how you
invoked the transformation and what the full error message was?
RE: Xalan extension functions
Posted by Sushy Behal <sb...@cisco.com>.
This works . Try this it would work too in your code if everything else is
fine
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl= <http://www.w3.org/1999/XSL/Transform>
http://www.w3.org/1999/XSL/Transform
xmlns= <http://www.w3.org/1999/xhtml> http://www.w3.org/1999/xhtml
xmlns:xalan= <http://xml.apache.org/xalan> http://xml.apache.org/xalan
xmlns:mytest="MyTest"
extension-element-prefixes="mytest"
version="1.0">
<xalan:component prefix="mytest" functions="nodeLinkRef ">
<xalan:script lang="javaclass" src="MyTest"/>
</xalan:component>
<!-- Somewhere in code -->
<xsl:value-of select="mytest:nodeLinkRef(.)"/>
//Modify JAVA CODE
import java.util.*;
//import all other relevant packages
public class MyTest
{
public Node nodeLinkRef(Node node)
{
try{
// do anything yu want here and beand this will handle exceptions
}
catch(Exception e)
{
e.printStackTrace();
}
return node;
}
}
Thanks
Sushy
_____
From: Wade, John F. (MSFC-NAS902099)[TBE] [mailto:John.F.Wade@nasa.gov]
Sent: Wednesday, May 02, 2007 6:50 AM
To: Wade, John F. (MSFC-NAS902099)[TBE]; Kevin Cormier
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
It's not Monday anymore. Oh well.
Here's the test case java code. It does exactly nothing.
Import java.util.*;
public class MyTest
{
public MyTest()
{}
}
The namespace and component definitions are:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl=http://www.w3.org/1999/XSL/Transform
xmlns=http://www.w3.org/1999/xhtml
xmlns:doc=http://nwalsh.com/xsl/documentation/1.0
exclude-result-prefixes="doc"
xmlns:xalan=http://xml.apache.org/xalan
xmlns:mytest="MyTest"
extension-element-prefixes="mytest"
version="1.0">
<xalan:component prefix="mytest" functions="MyTest">
<xalan:script lang="javaclass" src="xalan://MyTest/"/>
</xalan:component>
Down in one of the templates I've added a line that says:
<xsl:value-of select="mytest:MyTest()"/>
And the error I get is:
(Location of error unknown)XSLT Error
(javax.xml.transform.TransformerException):
javax.xml.transform.TransformerException: Instance method call to method
MyTest requires an Object instance as first argument
..which isn't the error I remember getting last time I tried this, but one
thing at a time.
Suggestions?
*********************************
John F. Wade, PE
MSFC EO20 - TBE
_____
From: Wade, John F. (MSFC-NAS902099)[TBE] [mailto:John.F.Wade@nasa.gov]
Sent: Fri 4/27/2007 3:29 PM
To: Kevin Cormier
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
Classpath has been my thought, too. I'm a real beginner at this, and the
environment I'm working with has two variants, so I'm not sure how to
determine what the classpath is in each case.
But, we'll start with the stylesheet and JAVA code on Monday and go from
there.
Thanks.
JFW
_____
From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
Sent: Fri 4/27/2007 3:11 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]
Cc: xalan-j-users@xml.apache.org
Subject: Re: Xalan extension functions
Hi John,
All I can think of with the information you've given is to check that your
class is on the classpath.
Could you send your stylesheet and Java class, and also show how you
invoked the transformation and what the full error message was?
RE: Xalan extension functions
Posted by "Wade, John F. (MSFC-NAS902099)[TBE]" <Jo...@nasa.gov>.
It's not Monday anymore. Oh well.
Here's the test case java code. It does exactly nothing.
Import java.util.*;
public class MyTest
{
public MyTest()
{}
}
The namespace and component definitions are:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl=http://www.w3.org/1999/XSL/Transform
xmlns=http://www.w3.org/1999/xhtml
xmlns:doc=http://nwalsh.com/xsl/documentation/1.0
exclude-result-prefixes="doc"
xmlns:xalan=http://xml.apache.org/xalan
xmlns:mytest="MyTest"
extension-element-prefixes="mytest"
version="1.0">
<xalan:component prefix="mytest" functions="MyTest">
<xalan:script lang="javaclass" src="xalan://MyTest/"/>
</xalan:component>
Down in one of the templates I've added a line that says:
<xsl:value-of select="mytest:MyTest()"/>
And the error I get is:
(Location of error unknown)XSLT Error (javax.xml.transform.TransformerException): javax.xml.transform.TransformerException: Instance method call to method MyTest requires an Object instance as first argument
...which isn't the error I remember getting last time I tried this, but one thing at a time.
Suggestions?
*********************************
John F. Wade, PE
MSFC EO20 - TBE
________________________________
From: Wade, John F. (MSFC-NAS902099)[TBE] [mailto:John.F.Wade@nasa.gov]
Sent: Fri 4/27/2007 3:29 PM
To: Kevin Cormier
Cc: xalan-j-users@xml.apache.org
Subject: RE: Xalan extension functions
Classpath has been my thought, too. I'm a real beginner at this, and the environment I'm working with has two variants, so I'm not sure how to determine what the classpath is in each case.
But, we'll start with the stylesheet and JAVA code on Monday and go from there.
Thanks.
JFW
________________________________
From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
Sent: Fri 4/27/2007 3:11 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]
Cc: xalan-j-users@xml.apache.org
Subject: Re: Xalan extension functions
Hi John,
All I can think of with the information you've given is to check that your
class is on the classpath.
Could you send your stylesheet and Java class, and also show how you
invoked the transformation and what the full error message was?
RE: Xalan extension functions
Posted by "Wade, John F. (MSFC-NAS902099)[TBE]" <Jo...@nasa.gov>.
Classpath has been my thought, too. I'm a real beginner at this, and the environment I'm working with has two variants, so I'm not sure how to determine what the classpath is in each case.
But, we'll start with the stylesheet and JAVA code on Monday and go from there.
Thanks.
JFW
________________________________
From: Kevin Cormier [mailto:kcormier@ca.ibm.com]
Sent: Fri 4/27/2007 3:11 PM
To: Wade, John F. (MSFC-NAS902099)[TBE]
Cc: xalan-j-users@xml.apache.org
Subject: Re: Xalan extension functions
Hi John,
All I can think of with the information you've given is to check that your
class is on the classpath.
Could you send your stylesheet and Java class, and also show how you
invoked the transformation and what the full error message was?
Re: Xalan extension functions
Posted by Kevin Cormier <kc...@ca.ibm.com>.
Hi John,
All I can think of with the information you've given is to check that your
class is on the classpath.
Could you send your stylesheet and Java class, and also show how you
invoked the transformation and what the full error message was?
Kevin Cormier
Software Developer, XSLT Development
IBM Toronto Lab, D1-435
E-mail: kcormier@ca.ibm.com
"Wade, John F.
(MSFC-NAS902099)[
TBE]" To
<John.F.Wade@nasa <xa...@xml.apache.org>
.gov> cc
04/27/2007 02:52 Subject
PM Xalan extension functions
As long as we're on the topic of XALAN extension functions, I too am
looking for some help. I've got an existing XALAN-J based system (I didn't
create it) that I'm trying to add on to. I want to create a simple
extension function in JAVA. The XALAN-J documentation says stuff written
in JAVA doesn't require BSF.
So - I went to work on one of the XSLs: added a simple namespace and
defined a component as in the example at
http://xml.apache.org/xalan-j/extensions.html#ex-java I wrote and compiled
an extension function; currently just of the "Hello, world" sort. So far,
so good.
Problem arises when I try and use the extension function in something like
<xsl:value-of select="mytest:hello()"/> XALAN throws a "can't find the
class" exception no matter where I put the .class file.
Those folks out there with some experience implementing JAVA extensions -
I'd be grateful for some help figuring this out. I'm sure it's something
very simple, but I don't know where to look next.
*********************************
John F. Wade, PE
MSFC iPV Integration Lead