/** Process conditionals and non-repeat attributes on an element */
  private void processElementInner(Node result, Element element) {
    TagHandler handler = registry.getHandlerFor(element);

    // An ugly special-case:  <os:Repeat> will re-evaluate the "if" attribute
    // (as it should) for each loop of the repeat.  Don't evaluate it here.
    if (!(handler instanceof RepeatTagHandler)) {
      Attr ifAttribute = element.getAttributeNode(ATTRIBUTE_IF);
      if (ifAttribute != null) {
        if (!evaluate(ifAttribute.getValue(), Boolean.class, false)) {
          return;
        }
      }
    }

    // TODO: the spec is silent on order of evaluation of "cur" relative
    // to "if" and "repeat"
    Attr curAttribute = element.getAttributeNode(ATTRIBUTE_CUR);
    Object oldCur = templateContext.getCur();
    if (curAttribute != null) {
      templateContext.setCur(evaluate(curAttribute.getValue(), Object.class, null));
    }

    if (handler != null) {
      handler.process(result, element, this);
    } else {
      // Be careful cloning nodes! If a target node belongs to a different document than the
      // template node then use importNode rather than cloneNode as that avoids side-effects
      // in UserDataHandlers where the cloned template node would belong to its original
      // document before being adopted by the target document.
      Element resultNode;
      if (element.getOwnerDocument() != result.getOwnerDocument()) {
        resultNode = (Element) result.getOwnerDocument().importNode(element, false);
      } else {
        resultNode = (Element) element.cloneNode(false);
      }

      clearSpecialAttributes(resultNode);
      Node additionalNode = processAttributes(resultNode);

      processChildNodes(resultNode, element);
      result.appendChild(resultNode);

      if (additionalNode != null) {
        result.appendChild(additionalNode);
      }
    }

    if (curAttribute != null) {
      templateContext.setCur(oldCur);
    }
  }