Re: setting TopLevel variables externally with XT

Subject: Re: setting TopLevel variables externally with XT
From: "Jon Smirl" <jonsmirl@xxxxxxxxxxxx>
Date: Wed, 28 Jul 1999 19:16:16 -0400
I just got this working. I figured it out by looking at how extension
functions are supported.

my servlet uses...
   xsl.setGlobal("browser", "string('" + s + "')");
   xsl.setGlobal("response", res);

stylesheet refers to $response with...

   <xsl:value-of select="logon:redirect($response)"/>

to implement in XT SheetImpl add....

  public void setGlobal(String variable, Object value) throws XSLException {
    Name var = nameTable.createName(variable);
    variableExprTable.put(var, new ExternalObjectExpr(value));

in xsl/epr add a new class...

  package com.jclark.xsl.expr;


  public class ExternalObjectExpr extends ConvertibleVariantExpr {
    private final Object obj;

    public ExternalObjectExpr(Object obj) {
      this.obj = obj;

    public Variant eval(Node node, ExprContext context) throws XSLException
      if (obj instanceof String)
        return new StringVariant((String)obj);
      if (obj instanceof Number)
        return new NumberVariant(((Number)obj).doubleValue());
      if (obj instanceof Boolean)
        return new BooleanVariant(((Boolean)obj).booleanValue());
      if (obj instanceof NodeIterator)
        return new NodeSetVariant((NodeIterator)obj);
      if (obj instanceof Node)
        return new NodeSetVariant(new SingleNodeIterator((Node)obj));
      if (obj instanceof Variant)
        return (Variant)obj;
      return new ObjectVariant(obj);

According to the spec there should be an <xsl:param name="response" /> Then
I wouldn't use createName on response I would check instead to make sure it
had been declared.

Jon Smirl

 XSL-List info and archive:

Current Thread