Index: genshi/template/markup.py
===================================================================
--- genshi/template/markup.py	(Revision 1127)
+++ genshi/template/markup.py	(Arbeitskopie)
@@ -343,6 +343,14 @@
                         del match_templates[idx]
                         idx -= 1
 
+                    # Make the select() function available in the body of the
+                    # match template
+                    selected = [False]
+                    def select(path):
+                        selected[0] = True
+                        return content.select(path, namespaces, ctxt)
+                    vars['select'] = select
+
                     # Let the remaining match templates know about the event so
                     # they get a chance to update their internal state
                     for test in [mt[0] for mt in match_templates[idx + 1:]]:
@@ -362,14 +370,6 @@
                         content = list(content)
                     content = Stream(content)
 
-                    # Make the select() function available in the body of the
-                    # match template
-                    selected = [False]
-                    def select(path):
-                        selected[0] = True
-                        return content.select(path, namespaces, ctxt)
-                    vars = dict(select=select)
-
                     # Recursively process the output
                     template = _apply_directives(template, directives, ctxt,
                                                  vars)
