Problem calling Java method in XSLT (Xalan)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robbie Baldock

    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:styleshe et
    version="1.0"
    xmlns:java="htt p://xml.apache.org/xslt/java"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:param name="requestCo ntext"/>
    <xsl:variable name="site" select="java:$r equestContext.g etCurrentSite() "/>
    </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


  • David Carlisle

    #2
    Re: Problem calling Java method in XSLT (Xalan)

    Robbie Baldock <me@privacy.net > writes:
    [color=blue]
    > 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:styleshe et
    > version="1.0"
    > xmlns:java="htt p://xml.apache.org/xslt/java"
    > xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    > <xsl:param name="requestCo ntext"/>
    > <xsl:variable name="site" select="java:$r equestContext.g etCurrentSite() "/>
    > </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[/color]

    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

    Comment

    • Stanimir Stamenkov

      #3
      Re: Problem calling Java method in XSLT (Xalan)

      /Robbie Baldock/:
      [color=blue]
      > <xsl:variable name="site" select="java:$r equestContext.g etCurrentSite() "/>[/color]

      Did you mean:

      <xsl:variable
      name="site">jav a:$requestConte xt.getCurrentSi te()</xsl:variable>

      or (the same):

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

      ?

      --
      Stanimir

      Comment

      • Stanimir Stamenkov

        #4
        Re: Problem calling Java method in XSLT (Xalan)

        /Stanimir Stamenkov/:[color=blue]
        > /Robbie Baldock/:
        >[color=green]
        >> <xsl:param name="requestCo ntext"/>[/color][/color]

        missed that one...
        [color=blue][color=green]
        >> <xsl:variable name="site" select="java:$r equestContext.g etCurrentSite() "/>[/color]
        >
        > Did you mean:
        >
        > <xsl:variable name="site">jav a:$requestConte xt.getCurrentSi te()</xsl:variable>[/color]

        or:

        <xsl:variable name="site">jav a:<xsl:value-of
        select="$reques tContext"/>.getCurrentSit e()</xsl:variable>

        I think it should be the same:

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

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

        --
        Stanimir

        Comment

        • Robbie

          #5
          Re: Problem calling Java method in XSLT (Xalan)

          On Thu, 24 Feb 2005 22:09:54 GMT, David Carlisle <davidc@nag.co. uk>
          wrote:
          [color=blue]
          >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.[/color]

          OK, I think I understand...!

          Thanks for the info.


          Robbie


          Comment

          • Robbie

            #6
            Re: Problem calling Java method in XSLT (Xalan)

            On Fri, 25 Feb 2005 00:37:13 +0200, Stanimir Stamenkov
            <s7an10@netscap e.net> wrote:
            [color=blue]
            >But reading through the David Carlisle's reply I realize you may be
            >trying something different.[/color]

            I shall try your various suggestions.

            Thanks for the response.


            Robbie


            Comment

            • Frank Meyer

              #7
              Re: Problem calling Java method in XSLT (Xalan)

              hi,
              [color=blue]
              > I've stripped the XSLT down to its bare bones:
              >
              > <xsl:styleshe et
              > version="1.0"
              > xmlns:java="htt p://xml.apache.org/xslt/java"
              > xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
              > <xsl:param name="requestCo ntext"/>
              > <xsl:variable name="site" select="java:$r equestContext.g etCurrentSite() "/>
              > </xsl:stylesheet>[/color]

              you have to use select="java:ge tCurrentSite($r equestContext)"

              regards
              frank

              Comment

              Working...