468,242 Members | 1,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,242 developers. It's quick & easy.

Problem calling Java method in XSLT (Xalan)

Hi -

I'm a bit of a newbie to the world of XSLTs but am trying to call a Java method on a parameter passed into an XSLT but
am having problems.

I've stripped the XSLT down to its bare bones:

<xsl:stylesheet
version="1.0"
xmlns:java="http://xml.apache.org/xslt/java"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="requestContext"/>
<xsl:variable name="site" select="java:$requestContext.getCurrentSite()"/>
</xsl:stylesheet>

But xsl:variable line produces the error:

"A node test that matches either NCName:* or QName was expected."

Can anyone spot where I'm going wrong?

Thanks for any suggestions.
Robbie
Jul 20 '05 #1
6 2906
Robbie Baldock <me@privacy.net> writes:
Hi -

I'm a bit of a newbie to the world of XSLTs but am trying to call a Java method on a parameter passed into an XSLT but
am having problems.

I've stripped the XSLT down to its bare bones:

<xsl:stylesheet
version="1.0"
xmlns:java="http://xml.apache.org/xslt/java"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="requestContext"/>
<xsl:variable name="site" select="java:$requestContext.getCurrentSite()"/>
</xsl:stylesheet>

But xsl:variable line produces the error:

"A node test that matches either NCName:* or QName was expected."

Can anyone spot where I'm going wrong?

Thanks for any suggestions.
Robbie


function names in xslt (as in C or java o most other languages) are
single tokens you can't use an expression to generate the name and you
can't replace part of teh name by a variable reference.

so you can use java:foo(....) if you have a method foo available but you
can't generate a funtion name from a parameter (unless you use an
evaluet() extension function taht parses a string as an Xpath
expression.

David

Jul 20 '05 #2
/Robbie Baldock/:
<xsl:variable name="site" select="java:$requestContext.getCurrentSite()"/>


Did you mean:

<xsl:variable
name="site">java:$requestContext.getCurrentSite()</xsl:variable>

or (the same):

<xsl:variable name="site"
select="'java:$requestContext.getCurrentSite()'"/>

?

--
Stanimir
Jul 20 '05 #3
/Stanimir Stamenkov/:
/Robbie Baldock/:
<xsl:param name="requestContext"/>
missed that one...
<xsl:variable name="site" select="java:$requestContext.getCurrentSite()"/>


Did you mean:

<xsl:variable name="site">java:$requestContext.getCurrentSite()</xsl:variable>


or:

<xsl:variable name="site">java:<xsl:value-of
select="$requestContext"/>.getCurrentSite()</xsl:variable>

I think it should be the same:

<xsl:variable name="site" select="concat('java:', $requestContext,
'.getCurrentSite()'"/>

But reading through the David Carlisle's reply I realize you may be
trying something different.

--
Stanimir
Jul 20 '05 #4
On Thu, 24 Feb 2005 22:09:54 GMT, David Carlisle <da****@nag.co.uk>
wrote:
so you can use java:foo(....) if you have a method foo available but you
can't generate a funtion name from a parameter (unless you use an
evaluet() extension function taht parses a string as an Xpath
expression.


OK, I think I understand...!

Thanks for the info.
Robbie
Jul 20 '05 #5
On Fri, 25 Feb 2005 00:37:13 +0200, Stanimir Stamenkov
<s7****@netscape.net> wrote:
But reading through the David Carlisle's reply I realize you may be
trying something different.


I shall try your various suggestions.

Thanks for the response.
Robbie
Jul 20 '05 #6
hi,
I've stripped the XSLT down to its bare bones:

<xsl:stylesheet
version="1.0"
xmlns:java="http://xml.apache.org/xslt/java"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="requestContext"/>
<xsl:variable name="site" select="java:$requestContext.getCurrentSite()"/>
</xsl:stylesheet>


you have to use select="java:getCurrentSite($requestContext)"

regards
frank

Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ravi Tallury | last post: by
1 post views Thread by hongping | last post: by
4 posts views Thread by Venkata Ramana Kala | last post: by
reply views Thread by Bloody Viking | last post: by
reply views Thread by Xiaolei Li | last post: by
3 posts views Thread by Petterson Mikael | last post: by
8 posts views Thread by Simon Brooke | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.