Problem calling Java method in XSLT (Xalan)

R

Robbie Baldock

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
 
D

David Carlisle

Robbie Baldock said:
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
 
S

Stanimir Stamenkov

/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()'"/>

?
 
S

Stanimir Stamenkov

/Stanimir Stamenkov/:
/Robbie Baldock/:

missed that one...
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.
 
R

Robbie

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
 
R

Robbie

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
 
Joined
Sep 15, 2006
Messages
1
Reaction score
0
requestContext Problem in XSL

Hi All ...

Even I gotta problem using the requestContext as xsl:param - and can anyone tell exactly what is the use of declaring it as a xsl:param instead of a normal xsl:variable ?

From where does the XSL processor get the requestContext Object ? should anything be done explicitly to get that object
or
just declaring it as a xsl:param will do ... ?

Waiting for solution,

Thanks,
Ram C

Robbie Baldock said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top