diff --git a/src/xmlpatterns/iterators/qitemmappingiterator_p.h b/src/xmlpatterns/iterators/qitemmappingiterator_p.h
index 9dc3b45ea0fca9880d4352ef4addbd36a111949a..3167bd748befe735fdeb1e4143a48ad21efbcd98 100644
--- a/src/xmlpatterns/iterators/qitemmappingiterator_p.h
+++ b/src/xmlpatterns/iterators/qitemmappingiterator_p.h
@@ -115,24 +115,28 @@ namespace QPatternist
          */
         virtual TResult next()
         {
-            const TSource sourceItem(m_it->next());
-
-            if(qIsForwardIteratorEnd(sourceItem))
-            {
-                m_current = TResult();
-                m_position = -1;
-                return TResult();
-            }
-            else
+            while (true)
             {
-                m_current = m_mapper->mapToItem(sourceItem, m_context);
-                if(qIsForwardIteratorEnd(m_current))
-                    return next(); /* The mapper returned null, so continue with the next in the source. */
-                else
+                const TSource &sourceItem = m_it->next();
+                if (qIsForwardIteratorEnd(sourceItem))
                 {
-                    ++m_position;
+                    m_current = TResult();
+                    m_position = -1;
                     return m_current;
                 }
+                else
+                {
+                    m_current = m_mapper->mapToItem(sourceItem, m_context);
+                    if (qIsForwardIteratorEnd(m_current))
+                    {
+                        continue; /* The mapper returned null, so continue with the next in the source. */
+                    }
+                    else
+                    {
+                        ++m_position;
+                        return m_current;
+                    }
+                }
             }
         }