1

I need to modify the file table in my trac browser view by creating a class which implements the ITemplateStreamfilter class. I tried using the Transformer from genshi.filters.transform. My table looks like

<tbody>
<tr class="even">
<td class="name">
<a class="partent" title="Parent Directory" ..>..</a>
</td>
..
</tr>
..
</tbody>

I now need to insert a </td> tag just before the frist cell in the first row of the table. The problem is that I only can identify the position of column where I want to put the new cell befor by searching for the "Parent Directory" title: Transformer('//*[@title="Parent Directory"]'). How can I step one tag up than put the new cell before the first <td class="name"> tag?

2
  • did you try it with genshi.edgewall.org/wiki/ApiDocs/… ?
    – falkb
    Nov 6, 2013 at 12:29
  • Yes, I tried it for hours. With all these methods I can only insert data before, in or after the current tag. But I need my data one more tag above the current.
    – x'mpl'
    Nov 8, 2013 at 17:29

1 Answer 1

1

I'm not THAT familiar with the support for XPATH of Transformer BUT:

What about Transformer('(//td[*[@title="Parent Directory"]])[1]') and then using the before method?

As far as I understand, this should select the first td node with a child node with an attribute title="Parent Directory".

If you want to select any td with that kind of child node use Transformer('//td[*[@title="Parent Directory"]]')

However, this only works if Transformer supports those XPATH expressions.

Edit 1

If you're sure, your td has an attribute class="name" you can also use Transformer('(//td[class="name" and *[@title="Parent Directory"]])[1]')

1
  • Thanks for the input. I tried your suggestions but the transformer does not accept an embed XPATH expression. What I did so far is Transformer('//tr[@class="even"]/td[@class="name"][1]').before(tag.td()) which puts the tag where I want it, but for all rows with class="even". It seems that the occurence selection [0] does not work either. Is there another way to tell the Transformer to only select the first occurence?
    – x'mpl'
    Nov 15, 2013 at 12:36

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.