cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donald Ball <ba...@webslingerZ.com>
Subject Re: how can I do this ?
Date Wed, 10 Jan 2001 18:24:57 GMT
On Wed, 10 Jan 2001, Piyush Sheth wrote:

>  my logicsheet looks like this
> -----
> ------
> ----
> <xsp:structure>mylib.*</xsp:structure>
> <xsp:logic>
>      private String get( String param )
>      {
>            new mylib.foo( param ).toString();
>      }
> </xsp:logic>
>
> <xsl:template match="mns:substitute"/>
> <!-- here I want call get("somethin") defined above
> and use its returned value in xsl:if.
>
> <xsl:if test=get("somethin")   .....
>
>
>
> -->
> </xsl:template>
> -------
> --------
> -------
> ------
>
> How do I do that ?

you're really mangling the logicsheet concept here. logicsheets are xslt
stylesheets which are applied to xsp pages to transform tags in special
namespaces into tags (and content) in the xsp namespace. e.g. this page

<esql:connection>
  <esql:driver>org.postgresql.Driver</esql:driver>
  ...
</esql:connection>

is transformed into (something like) this:

<xsp:logic>
  Class.forName("org.postgresql.Driver").newInstance();
  ...
</xsp:logic>

and then finally transformed into a java class.

okay so far? good. now, you're trying to evalute a java method inside an
xpath expression:

> <xsl:if test=get("somethin")   .....

you can't _do_ that. when your logicsheet is being applied, the java class
doesn't even _exist_ yet, you can't call one of its methods. you're in the
process of _creating_ the java class at logicsheet application time.

for the record, your logicsheet should look something more like this:

<xsl:template match="xsp:page">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsp:structure>
      <xsp:include>mylib.*</xsp:include>
    </xsp:structure>
    <xsp:logic>
      private String get(String param) {
        new mylib.foo( param ).toString();
      }
    </xsp:logic>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="mns:substitute">
  <xsp:logic>
    if ("bar".equals(get("foo"))) {
      ...
    }
  </xsp:logic>
</xsl:template>

<xsl:template match="@*|node()" priority="-1">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

- donald


Mime
View raw message