if ( indexMap == null ) throw new IllegalArgumentException( "You cannot use Remap nodes without an index map" );
final Reference2ReferenceArrayMap<Index, Index> indexInverseRemapping = new Reference2ReferenceArrayMap<Index, Index>( node.indexInverseRemapping.size() );
for( Map.Entry<String,String> e: node.indexInverseRemapping.entrySet() ) {
final Index externalIndex = indexMap.get( e.getKey() );
final Index internalIndex = indexMap.get( e.getValue() );
if ( internalIndex == null ) throw new NoSuchElementException( "The internal index \"" + e.getValue() + "\" does not appear in the index map (" + indexMap + ")" );
if ( externalIndex == null ) throw new NoSuchElementException( "The external index \"" + e.getKey() + "\" does not appear in the index map (" + indexMap + ")" );
indexInverseRemapping.put( externalIndex, internalIndex );
}
return new RemappingDocumentIterator( subNode, indexInverseRemapping );
}