protected Attribute setAttributeContent(
      Attribute target,
      StepList xpath,
      Object value,
      String id,
      AttributeType targetNodeType,
      boolean isXlinkRef,
      Expression sourceExpression,
      Object source,
      final Map<Name, Expression> clientProperties,
      boolean ignoreXlinkHref) {
    Attribute instance = null;

    Map<Name, Expression> properties = new HashMap<Name, Expression>(clientProperties);

    if (ignoreXlinkHref) {
      properties.remove(XLINK_HREF_NAME);
    }

    if (properties.containsKey(XLINK_HREF_NAME) && resolveDepth > 0) {
      // local resolve

      String refid =
          referenceToIdentifier(getValue(properties.get(XLINK_HREF_NAME), source).toString());

      if (refid != null) {

        final Hints hints = new Hints();
        if (resolveDepth > 1) {
          hints.put(Hints.RESOLVE, ResolveValueType.ALL);
          // only the top-level resolve thread should monitor timeout
          hints.put(Hints.RESOLVE_TIMEOUT, Integer.MAX_VALUE);
          hints.put(Hints.ASSOCIATION_TRAVERSAL_DEPTH, resolveDepth - 1);
        } else {
          hints.put(Hints.RESOLVE, ResolveValueType.NONE);
        }

        // let's try finding it
        FeatureFinder finder = new FeatureFinder(refid, hints);
        // this will be null if joining or sleeping is interrupted
        Feature foundFeature = null;
        if (resolveTimeOut == Integer.MAX_VALUE) {
          // not the top-level resolve thread so do not monitor timeout
          finder.run();
          foundFeature = finder.getFeature();
        } else {
          Thread thread = new Thread(finder);
          long startTime = System.currentTimeMillis();
          thread.start();
          try {
            while (thread.isAlive()
                && (System.currentTimeMillis() - startTime) / 1000 < resolveTimeOut) {
              Thread.sleep(RESOLVE_TIMEOUT_POLL_INTERVAL);
            }
            thread.interrupt();
            // joining ensures synchronisation
            thread.join();
            foundFeature = finder.getFeature();
          } catch (InterruptedException e) {
            // clean up as best we can
            thread.interrupt();
            throw new RuntimeException("Interrupted while resolving resource " + refid);
          }
        }

        if (foundFeature != null) {
          // found it
          instance =
              xpathAttributeBuilder.set(
                  target,
                  xpath,
                  Collections.singletonList(foundFeature),
                  id,
                  targetNodeType,
                  false,
                  sourceExpression);
          properties.remove(XLINK_HREF_NAME);
        }
      }
    }

    if (instance == null) {
      instance =
          xpathAttributeBuilder.set(
              target, xpath, value, id, targetNodeType, false, sourceExpression);
    }

    setClientProperties(instance, source, properties);

    return instance;
  }