eval method

  1. @override
XPathNodeset eval(
  1. DataInstance? model,
  2. EvaluationContext context
)
override

The nodeset this path selects: the path is anchored to the context node (or, for current(), the original context), expanded with predicates, and non-relevant nodes are dropped.

Port of XPathPathExprEval.

Implementation

@override
XPathNodeset eval(DataInstance? model, EvaluationContext context) {
  final ref = _reference.contextualize(
    _reference.contextType == ReferenceContext.original
        ? context.originalContext
        : context.contextRef,
  )!;
  final DataInstance instance;
  if (ref.instanceName != null && ref.isAbsolute) {
    instance =
        context.instanceNamed(ref.instanceName!) ??
        (throw XPathMissingInstanceException(
          ref.instanceName!,
          'Instance referenced by ${ref.toString(includePredicates: true)} '
          'does not exist',
        ));
  } else {
    instance =
        context.mainInstance ??
        (throw XPathException(
          'Cannot evaluate the reference '
          '[${ref.toString(includePredicates: true)}] in the current '
          'evaluation context. No default instance has been declared!',
        ));
  }
  if (instance.root == null) {
    throw XPathMissingInstanceException(
      ref.instanceName ?? '',
      'Instance referenced by ${ref.toString(includePredicates: true)} '
      'has not been loaded',
    );
  }
  return XPathNodeset(
    [
      for (final r in context.expandReference(ref)!)
        if (instance.resolveReference(r)!.isRelevant) r,
    ],
    instance,
    context,
  );
}