Index: genshi/template/tests/directives.py
===================================================================
--- genshi/template/tests/directives.py	(revision 1096)
+++ genshi/template/tests/directives.py	(working copy)
@@ -974,6 +974,37 @@
         self.assertNotEqual(None, matches)
         self.assertEqual(1, len(matches))
 
+    def test_match_multiple_times1(self):
+        # See http://genshi.edgewall.org/ticket/370
+        tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
+          <py:match path="body[@id='content']/h2" />
+          <head py:match="head" />
+          <head py:match="head" />
+          <head />
+          <body />
+        </html>""")
+        self.assertEqual("""<html>
+          <head/>
+          <body/>
+        </html>""", tmpl.generate().render())
+
+    def test_match_multiple_times2(self):
+        # See http://genshi.edgewall.org/ticket/370
+        tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
+          <py:match path="body/div[@id='properties']" />
+          <head py:match="head" />
+          <head py:match="head" />
+          <head/>
+          <body>
+            <div id="properties">Foo</div>
+          </body>
+        </html>""")
+        self.assertEqual("""<html>
+          <head/>
+          <body>
+          </body>
+        </html>""", tmpl.generate().render())
+
     # FIXME
     #def test_match_after_step(self):
     #    tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
Index: genshi/template/markup.py
===================================================================
--- genshi/template/markup.py	(revision 1096)
+++ genshi/template/markup.py	(working copy)
@@ -391,7 +391,7 @@
                     # Let the remaining match templates know about the last
                     # event in the matched content, so they can update their
                     # internal state accordingly
-                    for test in [mt[0] for mt in match_templates]:
+                    for test in [mt[0] for mt in match_templates[idx + 1:]]:
                         test(tail[0], namespaces, ctxt, updateonly=True)
 
                     break
