getTemplatePath method

TreeElement? getTemplatePath(
  1. TreeReference ref
)

The node at ref following templates where present, otherwise the first instance of each step.

Implementation

TreeElement? getTemplatePath(TreeReference ref) {
  if (!ref.isAbsolute) return null;
  TreeElement? walker;
  var node = base;
  for (var i = 0; i < ref.size; i++) {
    final name = ref.nameAt(i);
    if (ref.multiplicityAt(i) == TreeReference.indexAttribute) {
      final attribute = node.getAttribute(null, name);
      if (attribute == null) return null;
      node = walker = attribute;
    } else {
      final next =
          node.getChild(name, TreeReference.indexTemplate) ??
          node.getChild(name, 0);
      if (next == null) return null;
      node = walker = next;
    }
  }
  return walker;
}