By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,903 Members | 1,922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,903 IT Pros & Developers. It's quick & easy.

Problem calling Java method in XSLT (Xalan)

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
/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

P: n/a
/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

P: n/a
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

P: n/a
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

P: n/a
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.