Source:
<code>private void applyIncludes(Node source, final Properties variablesContext) { if (source.getNodeName().equals("include")) { Properties fullContext; String refid = getStringAttribute(source, "refid"); refid = PropertyParser.parse(refid, variablesContext); Node toInclude = findSqlFragment(refid); Properties newVariablesContext = getVariablesContext(source); if (!newVariablesContext.isEmpty()) { for (Object name : newVariablesContext.keySet()) { newVariablesContext.put(name, PropertyParser.parse(newVariablesContext.get(name).toString(), variablesContext)); } applyInheritedContext(newVariablesContext, variablesContext); fullContext = newVariablesContext; } else { fullContext = variablesContext; } <START> applyIncludes(toInclude, fullContext); <END> if (toInclude.getOwnerDocument() != source.getOwnerDocument()) { toInclude = source.getOwnerDocument().importNode(toInclude, true); } source.getParentNode().replaceChild(toInclude, source); while (toInclude.hasChildNodes()) { toInclude.getParentNode().insertBefore(toInclude.getFirstChild(), toInclude); } toInclude.getParentNode().removeChild(toInclude); } else if (source.getNodeType() == Node.ELEMENT_NODE) { NodeList children = source.getChildNodes(); for (int i=0; i<children.getLength(); i++) { applyIncludes(children.item(i), variablesContext); } } else if (source.getNodeType() == Node.ATTRIBUTE_NODE && !variablesContext.isEmpty()) { source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext)); } else if (source.getNodeType() == Node.TEXT_NODE && !variablesContext.isEmpty()) { source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext)); } }</code><technical_language>This part simpler if replacing variables in subroutine. do think? java Properties fullContext; Properties childContext = getVariablesContext(source, variablesContext); if (childContext.isEmpty()) { fullContext = variablesContext; } else { fullContext = new Properties(); fullContext.putAll(variablesContext); fullContext.putAll(childContext); } applyIncludes(toInclude, fullContext); I missing something, though</technical_language>

Target:
private void applyIncludes(Node source, final Properties variablesContext) { if (source.getNodeName().equals("include")) { Properties fullContext; String refid = getStringAttribute(source, "refid"); refid = PropertyParser.parse(refid, variablesContext); Node toInclude = findSqlFragment(refid); Properties newVariablesContext = getVariablesContext(source, variablesContext); if (!newVariablesContext.isEmpty()) { fullContext = new Properties(); fullContext.putAll(variablesContext); fullContext.putAll(newVariablesContext); } else { fullContext = variablesContext; } applyIncludes(toInclude, fullContext); if (toInclude.getOwnerDocument() != source.getOwnerDocument()) { toInclude = source.getOwnerDocument().importNode(toInclude, true); } source.getParentNode().replaceChild(toInclude, source); while (toInclude.hasChildNodes()) { toInclude.getParentNode().insertBefore(toInclude.getFirstChild(), toInclude); } toInclude.getParentNode().removeChild(toInclude); } else if (source.getNodeType() == Node.ELEMENT_NODE) { NodeList children = source.getChildNodes(); for (int i=0; i<children.getLength(); i++) { applyIncludes(children.item(i), variablesContext); } } else if (source.getNodeType() == Node.ATTRIBUTE_NODE && !variablesContext.isEmpty()) { source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext)); } else if (source.getNodeType() == Node.TEXT_NODE && !variablesContext.isEmpty()) { source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext)); } }