Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Problem calling Java method in XSLT (Xalan)

Reply
Thread Tools

Problem calling Java method in XSLT (Xalan)

 
 
Robbie Baldock
Guest
Posts: n/a
 
      02-24-2005
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslaram 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


 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      02-24-2005
Robbie Baldock <> 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"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">
> <xslaram 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

 
Reply With Quote
 
 
 
 
Stanimir Stamenkov
Guest
Posts: n/a
 
      02-24-2005
/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
 
Reply With Quote
 
Stanimir Stamenkov
Guest
Posts: n/a
 
      02-24-2005
/Stanimir Stamenkov/:
> /Robbie Baldock/:
>
>> <xslaram 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
 
Reply With Quote
 
Robbie
Guest
Posts: n/a
 
      02-24-2005
On Thu, 24 Feb 2005 22:09:54 GMT, David Carlisle <>
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


 
Reply With Quote
 
Robbie
Guest
Posts: n/a
 
      02-24-2005
On Fri, 25 Feb 2005 00:37:13 +0200, Stanimir Stamenkov
<> 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


 
Reply With Quote
 
Frank Meyer
Guest
Posts: n/a
 
      02-26-2005
hi,

> I've stripped the XSLT down to its bare bones:
>
> <xsl:stylesheet
> version="1.0"
> xmlns:java="http://xml.apache.org/xslt/java"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">
> <xslaram name="requestContext"/>
> <xsl:variable name="site" select="java:$requestContext.getCurrentSite()"/>
> </xsl:stylesheet>


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

regards
frank

 
Reply With Quote
 
Ram C Ram C is offline
Junior Member
Join Date: Sep 2006
Posts: 1
 
      09-15-2006
Hi All ...

Even I gotta problem using the requestContext as xslaram - and can anyone tell exactly what is the use of declaring it as a xslaram 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 xslaram will do ... ?

Waiting for solution,

Thanks,
Ram C

Quote:
Originally Posted by 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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslaram 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Poll: Is a Java Method an Instance of the Java Classjava.lang.reflect.Method? Please reply with YES or NO. Paka Small Java 15 02-07-2012 07:04 PM
Calling a method of the calling object ... why-em-jay Perl Misc 3 09-15-2005 07:53 PM
xslt alone or xslt/java for static site? ted XML 1 01-26-2004 10:41 AM
Urgent: Calling a method of a java object (getting a boolean parameter) from java script Eyal Javascript 2 08-07-2003 11:49 AM
Problems with JNI: calling a Java method from native method. Jabel D. Morales - VMan of Mana Java 1 08-01-2003 12:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57