Edgewall Software

Ticket #187 (closed defect: worksforme)

Opened 7 years ago

Last modified 3 years ago

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())


Change History

Changed 7 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.

Changed 7 years ago by cmlenz

See also #186.

Changed 7 years ago by cmlenz

  • component changed from General to Template processing

Changed 7 years ago by cmlenz

  • status changed from new to closed
  • resolution set to worksforme
  • milestone 0.5 deleted

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/Change #187 (Hierarchical matches do not work correctly across a py:match)


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

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'
Note: See TracTickets for help on using tickets.