Index: /CKEditor/trunk/CHANGES.html
===================================================================
--- /CKEditor/trunk/CHANGES.html	(revision 7606)
+++ /CKEditor/trunk/CHANGES.html	(revision 7607)
@@ -54,4 +54,5 @@
 		<li><a href="http://dev.ckeditor.com/ticket/9117">#9117</a> : [FF] Avoid js error when calling setData() on a hidden editor.</li>
 		<li><a href="http://dev.ckeditor.com/ticket/9289">#9289</a> : Disallow creating javascript: links through the link dialog.</li>
+		<li><a href="http://dev.ckeditor.com/ticket/9312">#9312</a> : Fixed table with multiple &lt;tbody&gt; output in wrong order.</li>
 	</ul>
 	<h3>
Index: /CKEditor/trunk/_source/plugins/htmldataprocessor/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/htmldataprocessor/plugin.js	(revision 7606)
+++ /CKEditor/trunk/_source/plugins/htmldataprocessor/plugin.js	(revision 7607)
@@ -20,4 +20,9 @@
 			last = block.children[ --lastIndex ];
 		return last;
+	}
+
+	function getNodeIndex( node ) {
+		var parent = node.parent;
+		return parent ? CKEDITOR.tools.indexOf( parent.children, node ) : -1;
 	}
 
@@ -160,10 +165,27 @@
 				table : function( element )
 				{
-					var children = element.children;
+					// Clone the array as it would become empty during the sort call.
+					var children = element.children.slice( 0 );
 					children.sort( function ( node1, node2 )
 								   {
-									   return node1.type == CKEDITOR.NODE_ELEMENT && node2.type == node1.type ?
-											CKEDITOR.tools.indexOf( tableOrder, node1.name )  > CKEDITOR.tools.indexOf( tableOrder, node2.name ) ? 1 : -1 : 0;
-								   } );
+										 var index1, index2;
+
+										 // Compare in the predefined order.
+										 if ( node1.type == CKEDITOR.NODE_ELEMENT &&
+													node2.type == node1.type )
+										 {
+											 index1 = CKEDITOR.tools.indexOf( tableOrder, node1.name );
+											 index2 = CKEDITOR.tools.indexOf( tableOrder, node2.name );
+										 }
+
+										 // Make sure the sort is stable, if no order can be established above.
+										 if ( !( index1 > -1 && index2 > -1 && index1 != index2 ) )
+										 {
+											 index1 = getNodeIndex( node1 );
+											 index2 = getNodeIndex( node2 );
+										 }
+
+										 return index1 > index2 ? 1 : -1;
+									 } );
 				},
 
