getVariable method

XPathSequence getVariable(
  1. String name
)

Looks up an XPath variable with the given name.

Implementation

XPathSequence getVariable(String name) {
  // Find the variable in the context chain.
  XPathContext? context = this;
  while (context != null) {
    final variable = context.variables[name];
    if (variable != null) return variable;
    context = context.parentContext;
  }
  // If not found, check the static context.
  final variable = configuration.variables[name];
  if (variable != null) return variable;
  // If still not found, throw an exception.
  throw XPathEvaluationException(
    XPathErrorCode.XPST0008,
    'Unknown variable: $name',
  );
}