Problem calling Java method in XSLT (Xalan)

Discussion in 'XML' started by Robbie Baldock, Feb 24, 2005.

  1. 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
     
    Robbie Baldock, Feb 24, 2005
    #1
    1. Advertising

  2. 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"
    > 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
     
    David Carlisle, Feb 24, 2005
    #2
    1. Advertising

  3. /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
     
    Stanimir Stamenkov, Feb 24, 2005
    #3
  4. /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
     
    Stanimir Stamenkov, Feb 24, 2005
    #4
  5. Robbie Baldock

    Robbie Guest

    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
     
    Robbie, Feb 24, 2005
    #5
  6. Robbie Baldock

    Robbie Guest

    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
     
    Robbie, Feb 24, 2005
    #6
  7. Robbie Baldock

    Frank Meyer Guest

    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
     
    Frank Meyer, Feb 26, 2005
    #7
  8. Robbie Baldock

    Ram C

    Joined:
    Sep 15, 2006
    Messages:
    1
    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

     
    Ram C, Sep 15, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christopher Blunck

    Re: XSLT Performance with Xalan

    Christopher Blunck, Jul 29, 2003, in forum: Java
    Replies:
    1
    Views:
    400
    Bradley E. Rintoul
    Jul 29, 2003
  2. satish mn via JavaKB.com
    Replies:
    0
    Views:
    416
    satish mn via JavaKB.com
    Nov 25, 2004
  3. RC
    Replies:
    6
    Views:
    646
    Martin Honnen
    Apr 22, 2005
  4. Peter Votruba

    Re: XSLT : Xalan wrong behaviour ?

    Peter Votruba, Jul 9, 2003, in forum: XML
    Replies:
    0
    Views:
    809
    Peter Votruba
    Jul 9, 2003
  5. cvissy
    Replies:
    0
    Views:
    616
    cvissy
    Nov 16, 2004
Loading...

Share This Page