﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc
77,Match templates can match their own output,dackze+genshi@…,cmlenz,"This is really hurting my head and I'm not exactly sure how to explain this, so here are some examples:

{{{
#!xml
<html xmlns=""http://www.w3.org/1999/xhtml""
      xmlns:py=""http://genshi.edgewall.org/"">
  <body py:match=""body"" py:content=""select('*')"" />
  <h1 py:match=""h1"">
    ${select('text()')}
    Goodbye!
  </h1>

  <body>
    <h1>Hello!</h1>
  </body>
</html>
}}}

Produces:

{{{
#!xml
<html xmlns=""http://www.w3.org/1999/xhtml"">
  <body><h1>
    Hello!
    Goodbye!
    Goodbye!
  </h1></body>
</html>
}}}

It seems to be triggered by the first match template outputting what the second match template matches, ''and'' by the name of the second match template matching its own query. If you make the first match template not output the `<h1>Hello</h1>` element, or change the `<h1 py:match=""h1"">` element to not match its own query, the problem disappears.

I'm not sure if this is intentional, but for what it's worth, Kid doesn't seem to behave this way:

{{{
#!xml
<html xmlns=""http://www.w3.org/1999/xhtml""
      xmlns:py=""http://purl.org/kid/ns#"">
  <body py:match=""item.tag == '{http://www.w3.org/1999/xhtml}body'""
        py:content=""[item.text] + item[:]"" />
  <h1 py:match=""item.tag == '{http://www.w3.org/1999/xhtml}h1'"">
    ${item.text}
    Goodbye!
  </h1>

  <body>
    <h1>Hello!</h1>
  </body>
</html>
}}}

Produces:

{{{
#!xml
<?xml version=""1.0"" encoding=""utf-8""?>
<html xmlns=""http://www.w3.org/1999/xhtml"">



  <body>
    <h1>
    Hello!
    Goodbye!
  </h1>
  </body>
}}}

The examples are contrived, but I originally ran into this with a form template that filled in fields via match templates. I had a match template that put error messages beneath fields with invalid input, and when I threw a match-based layout template into the mix, I started getting two of each error list.

Also, this seems to happen in all of the current branches, the current trunk, and all of the 0.3 tags.",defect,closed,major,0.3.5,Template processing,devel,fixed,,
