#187 closed defect (worksforme)
Hierarchical matches do not work correctly across a py:match
Reported by: | Matt Chaput <matt@…> | Owned by: | cmlenz |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | Template processing | Version: | devel |
Keywords: | Cc: |
Description
In the following example, the second py:match (a/b) should match the <b /> below, but because the surrounding <a> element is a py:match, the hierachical match apparently does not see the a tag.
from genshi.template import MarkupTemplate tmpl = MarkupTemplate("""<?xml version="1.0" ?> <test xmlns:py="http://genshi.edgewall.org/"> <py:match path="a">${select('*')}</py:match> <py:match path="a/b">Right</py:match> <py:match path="b">Wrong</py:match> <a><b /></a> </test> """) print unicode(tmpl.generate())
Change History (4)
comment:1 Changed 17 years ago by Matt Chaput <matt@…>
comment:2 Changed 17 years ago by cmlenz
See also #186.
comment:3 Changed 17 years ago by cmlenz
- Component changed from General to Template processing
comment:4 Changed 17 years ago by cmlenz
- Milestone 0.5 deleted
- Resolution set to worksforme
- Status changed from new to closed
Okay, here's an explanation of the behavior (at least since [810], see also #186):
The first match template matches the <a> element, and basically produces <b /> due to the select("*") expression. The second match template doesn't match anything, as the first removed the <a> tag. The third then matches the <b /> tag.
You'd need to use select(".") for this example to make sense, as that doesn't strip off the <a> tags.
It seems like the path matches the generated parent, not the original parent. Which may be a limitation of Genshi, but makes it hard/impossible to use py:match in a hierarchical XSLT-like way in many cases.