Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 7th, 2005, 05:17 AM
Registered User
 
Join Date: Oct 2005
Location: Edinburgh, , United Kingdom.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem calling static Java functions from XSLT

Hi all,

I'm having a spot of bother trying to get my XSLT to call external java functions. I am needing the equivalent of Math.pow(a,b). I have declared a java namespace on the stylesheet, as such:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:java="c://projects/blah/classes/net/blah/transforms"
                exclude-result-prefixes="java">

where my function is a static function in a class called 'Functions' which is in the 'transforms' package. When I try to call it using:

<xsl:value-of select="java:Functions.power(@n)"/>

I get a ClassNotFoundException: transforms/Functions

If I change the namespace path to be /transforms/Functions and call it with 'select="java:power(@n)"' then I get

java.lang.NoSuchMethodException: For extension function, could not find method org.apache.xpath.objects.XNodeSet.power([ExpressionContext,] ).

I am sure I am just missing something obvious, if anyone can point out what I am doing wrong I would be very grateful, thanks!


Reply With Quote
  #2 (permalink)  
Old October 7th, 2005, 05:21 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

The way extension functions work depend on which XSLT processor you are using, so that's the first thing you need to tell us.

From the error message, it looks as if you're using Xalan, in which case it might be best to ask on a Xalan list.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old October 7th, 2005, 07:53 AM
Registered User
 
Join Date: Oct 2005
Location: Edinburgh, , United Kingdom.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah, apologies for the oversight. Yes I am using the Xalan processor, although to be honest I don't really care which I have to use, as this is the only part of a large project that is using XSLT, so I am free to use whichever gets the job done. Would you be able to help with any other transformer?


Reply With Quote
  #4 (permalink)  
Old October 7th, 2005, 10:11 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

I can certainly give you help if you decide to use Saxon.

For info on writing extension functions with Saxon, see http://www.saxonica.com/documentatio...functions.html

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old October 10th, 2005, 05:23 AM
Registered User
 
Join Date: Oct 2005
Location: Edinburgh, , United Kingdom.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the link. I was interested to note that I could call java functions easily using Saxon, as like I said above it's only Math.pow() I need at this point. So now I have

<xsl:value-of select="math:pow($currentAge,$startAge)" xmlns:math="java:java.lang.Math"/>

But of course this fails as I have not declared the java namespace yet. I am at a loss as to what this should be declared as though?

Thanks again.


Reply With Quote
  #6 (permalink)  
Old October 10th, 2005, 05:47 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

Your code looks correct to me: if $currentAge and $startAge are doubles I would expect it to work. How is it failing, and which Saxon version are you using?

(There's no "java" namespace here. The prefix "java:" is being used as part of the namespace URI - technically, the scheme name of the URI).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #7 (permalink)  
Old October 10th, 2005, 07:24 AM
Registered User
 
Join Date: Oct 2005
Location: Edinburgh, , United Kingdom.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Heh, I'm an idiot. The error was a leftover 'exclude-result-prefixes="java"' statement in the header, from when I was trying to get it to work with Xalan. :)

Many thanks for all your help!


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help calling and using a functions in visual c++ 6 method Visual C++ 0 July 8th, 2006 05:20 PM
Calling functions ejmichaud Access VBA 2 July 16th, 2004 10:03 AM
calling functions with conditions Toka1 Javascript How-To 2 February 5th, 2004 09:29 AM
Calling functions in Windows? jacob C# 0 November 5th, 2003 03:57 PM
Calling subs & Functions Zooker Beginning VB 6 4 August 20th, 2003 07:09 PM



All times are GMT -4. The time now is 10:23 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.