+ SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential);
+ if (originalDefinition.equals(potentialRoot)) {
+ return Optional.of(potential);
+ }
+ }
+ // We try to find case by name, then lookup its root definition
+ // and compare it with original definition
+ // This solves case, if choice was inside grouping
+ // which was used in different module and thus namespaces are
+ // different, but local names are still same.
+ //
+ // Still we need to check equality of definition, because local name is not
+ // sufficient to uniquelly determine equality of cases
+ //
+ potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName().getLocalName());
+ if(potential != null && (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(potential)))) {