Edgewall Software

Opened 12 years ago

Last modified 7 years ago

#521 new defect

genshi can't select xpath element based on its contents — at Initial Version

Reported by: Chad Phillips <chad@…> Owned by: cmlenz
Priority: major Milestone: 0.9
Component: General Version: 0.6
Keywords: Cc: chad@…, leho@…

Description

While customizing my Trac installation, I ran across a particularly sticky problem: it does not seem possible to use the contains() xpath function in genshi in a way that allows conditionally selecting an element based on its contents.

The particular example are labels in the change history for Trac. These are inside strong tags, but have no tag metadata to use for the xpath selector, so matching on the contents of the strong tag is the only way to alter the ones I want.

The non-working code that I believe should work:

Champion:

Also tried text() instead of . in contains(), that also errors out.

Here is the code I finally got to work, after literally hours of screwing around and research:

If I hadn't eventually realized that select() is represented as a stream instead of a string, I never would have gotten this working, either. Thankfully the documentation at http://genshi.edgewall.org/wiki/Documentation/0.5.x/streams.html#serialization provided me with the render() method so I could finally compare strings in py:choose.

I'd like to strongly advocate that contains() be fixed to work properly, as it shouldn't be necessary to jump through all these hoops in order to match on an element's contents.

Change History (0)

Note: See TracTickets for help on using tickets.