Edgewall Software

Opened 10 years ago

Closed 10 years ago

Last modified 6 years ago

#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:


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>

print unicode(tmpl.generate())

Attachments (0)

Change History (4)

comment:1 Changed 10 years ago by Matt Chaput <matt@…>

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.

comment:2 Changed 10 years ago by cmlenz

See also #186.

comment:3 Changed 10 years ago by cmlenz

  • Component changed from General to Template processing

comment:4 Changed 10 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.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain cmlenz.
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.