Пример #1
0
  /**
   * Find the string value of a stylesheet variable or parameter
   *
   * <p>Returns the string value of <code>varName</code> in the current <code>context</code>.
   * Returns the empty string if the variable is not defined.
   *
   * @param context The current stylesheet context
   * @param varName The name of the variable (without the dollar sign)
   * @return The string value of the variable
   */
  protected static String getVariable(Context context, String varName) {
    Value variable = null;
    String varString = null;

    try {
      variable = Extensions.evaluate(context, "$" + varName);
      varString = variable.asString();
      return varString;
    } catch (TransformerException te) {
      System.out.println("Undefined variable: " + varName);
      return "";
    } catch (IllegalArgumentException iae) {
      System.out.println("Undefined variable: " + varName);
      return "";
    }
  }