@Override
    protected boolean extractImpl(XPathExpression expression, Set<XPathExpression> matchingExpressions, List<XmlTag> otherMatches, IntroduceVariableOptions dlg) {
        final XmlAttribute attribute = PsiTreeUtil.getContextOfType(expression, XmlAttribute.class, true);
        assert attribute != null;

        try {
            final String name = dlg.getName();
            final XmlTag insertionPoint = XsltCodeInsightUtil.findVariableInsertionPoint(
                    attribute.getParent(),
                    XsltCodeInsightUtil.getUsageBlock(expression),
                    name,
                    dlg.isReplaceAll() ? otherMatches.toArray(XmlTag.EMPTY) : XmlTag.EMPTY);

            final XmlTag parentTag = insertionPoint.getParentTag();
            assert parentTag != null : "Could not locate position to create variable at";

            final XmlTag xmlTag = parentTag.createChildTag("variable", XsltSupport.XSLT_NS, null, false);
            xmlTag.setAttribute("name", name);
            xmlTag.setAttribute("select", expression.getText());

            // TODO: revisit the formatting
            final PsiElement element = parentTag.addBefore(xmlTag, insertionPoint);
            final ASTNode node1 = parentTag.getNode();
            assert node1 != null;
            final ASTNode node2 = element.getNode();
            assert node2 != null;
          CodeStyleManager.getInstance(xmlTag.getManager().getProject()).reformatNewlyAddedElement(node1, node2);

            final XPathVariableReference var = XPathChangeUtil.createVariableReference(expression, name);
            expression.replace(var);

            if (dlg.isReplaceAll()) {
                for (XPathExpression expr : matchingExpressions) {
                    expr.replace(XPathChangeUtil.createVariableReference(expr, name));
                }
                return false;
            } else {
                return true;
            }
        } catch (IncorrectOperationException e) {
            Logger.getInstance(getClass().getName()).error(e);
            return false;
        }
    }
@Override
    protected boolean extractImpl(XPathExpression expression, Set<XPathExpression> matchingExpressions, List<XmlTag> otherMatches, IntroduceVariableOptions dlg)