Have to send endCompose to the sort elements, or the mark
stack will not be properly popped.

diff --git a/src/org/apache/xalan/templates/ElemForEach.java b/src/org/apache/xalan/templates/ElemForEach.java
index 928c9b2..35dd0d8 100644
--- a/src/org/apache/xalan/templates/ElemForEach.java
+++ b/src/org/apache/xalan/templates/ElemForEach.java
@@ -170,6 +170,22 @@
         getStylesheetRoot().m_selectDefault.getExpression();
     }
   }
+  
+  /**
+   * This after the template's children have been composed.
+   */
+  public void endCompose(StylesheetRoot sroot) throws TransformerException
+  {
+    int length = getSortElemCount();
+
+    for (int i = 0; i < length; i++)
+    {
+      getSortElem(i).endCompose(sroot);
+    }
+    
+    super.endCompose(sroot);
+  }
+
 
   //  /**
   //   * This function is called after everything else has been