private @NotNull List<Element> resolveXIncludeElement(@NotNull Element element, @NotNull Stack<URL> bases)
    throws XIncludeException, MalformedURLException {
    URL base = null;
    if (!bases.isEmpty()) {
      base = bases.peek();
    }

    String href = element.getAttributeValue("href");
    assert href != null : "Missing href attribute";

    String baseAttribute = element.getAttributeValue("base", Namespace.XML_NAMESPACE);
    if (baseAttribute != null) {
      base = new URL(baseAttribute);
    }

    final String parseAttribute = element.getAttributeValue("parse");
    if (parseAttribute != null) {
      LOG.assertTrue(parseAttribute.equals("xml"), parseAttribute + " is not a legal value for the parse attribute");
    }

    URL remote = myPathResolver.resolvePath(href, base);
    assert !bases.contains(remote) : "Circular XInclude Reference to " + remote.toExternalForm();

    final Element fallbackElement = element.getChild("fallback", element.getNamespace());
    List<Element> remoteParsed = parseRemote(bases, remote, fallbackElement);
    if (!remoteParsed.isEmpty()) {
      remoteParsed = extractNeededChildren(element, remoteParsed);
    }

    int i = 0;
    for (; i < remoteParsed.size(); i++) {
      Element o = remoteParsed.get(i);
      if (isIncludeElement(o)) {
        List<Element> elements = resolveXIncludeElement(o, bases);
        remoteParsed.addAll(i, elements);
        i += elements.size() - 1;
        remoteParsed.remove(i);
      }
      else {
        resolveNonXIncludeElement(o, bases);
      }
    }

    for (Content content : remoteParsed) {
      content.detach();
    }
    return remoteParsed;
  }
private @NotNull List<Element> resolveXIncludeElement(@NotNull Element element, @NotNull Stack<URL> bases)