+ string tag = reinterpret_cast<const char *>(child->name);
+
+ // Attribute substitution.
+ if (begins_with(it.first, tag + "/")) {
+ const xmlChar *attr_key = reinterpret_cast<const xmlChar *>(
+ it.first.substr(tag.size() + 1).c_str());
+ const xmlChar *attr_value = reinterpret_cast<const xmlChar *>(
+ it.second->get_contents().c_str());
+ xmlSetProp(child, attr_key, attr_value);
+ } else if ((!id.empty() && begins_with(it.first, "#" + id + "/"))) {
+ const xmlChar *attr_key = reinterpret_cast<const xmlChar *>(
+ it.first.substr(tag.size() + 2).c_str());
+ const xmlChar *attr_value = reinterpret_cast<const xmlChar *>(
+ it.second->get_contents().c_str());
+ xmlSetProp(child, attr_key, attr_value);
+ }
+
+ if (processed) {
+ continue;
+ }
+
+ // Regular substitution.
+ if (it.first == tag ||